laravel集成gatewayWorker启动时报一个php文件不能同时启动多个worker,要怎么改

chenStudy

截图截图

6056 12 0
12个回答

nitron
  • chenStudy 2022-09-27

    这个文档里面不太具体,我这种方式的要怎样拆分成三个呢

xiuwang

laravel自带命令行,感觉和文档里windows启动多个worker冲突,要么拆成三个命令分别执行,要么用linux系统吧

  • chenStudy 2022-09-27

    那分成三个什么样子的呢

  • xiuwang 2022-09-27

    分成三个命令
    php artisan gateway-worker:register start
    php artisan gateway-worker:gateway start
    php artisan gateway-worker:worker start

不败少龙

在Windows下都会报那个链接 其实不影响使用

chenStudy

截图

  • 暂无评论
chenStudy

截图,这样嘛

  • 暂无评论
不败少龙
<?php

namespace App\Console\Commands;

use App\GatewayWorker\Events;
use Illuminate\Console\Command;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use Workerman\Worker;

class GatewayService extends Command
{
    /**
     *
     * 程序的根目录下执行 php artisan workman start
     *   php artisan workman start --d
     * @var string
     */
    protected $signature = 'workman {action} {--d}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Start a Workerman server.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        global $argv;
        $action = $this->argument('action');

        $argv[0] = 'artisan workman';
        $argv[1] = $action;
        $argv[2] = $this->option('d') ? '-d' : '';   //必须是一个-,上面定义命令两个--,后台启动用两个--

        $this->start();
    }

    private function start()
    {
        $this->startGateWay();
        $this->startBusinessWorker();
        $this->startRegister();
        Worker::runAll();
    }

    private function startBusinessWorker()
    {
        $worker = new BusinessWorker();
        $worker->name = 'BusinessWorker';
        $worker->count = 1;
        $worker->registerAddress = '127.0.0.1:1236';
        $worker->eventHandler = Events::class;
    }

    private function startGateWay()
    {
        $gateway = new Gateway("tcp://0.0.0.0:2347");
        $gateway->name = 'Gateway';
        $gateway->count = 4;
        $gateway->lanIp = '127.0.0.1';
        $gateway->startPort = 40001;
        $gateway->pingInterval = 30;
        $gateway->pingNotResponseLimit = 0;
        $gateway->pingData = '{"type":"ping"}';
        $gateway->registerAddress = '127.0.0.1:1236';

    }

    private function startRegister()
    {
        new Register('text://0.0.0.0:1236');
    }
}
chenStudy

截图报这个

chenStudy

截图,这是另外一种直接下载放进去的在win系统下面可以

  • chenStudy 2022-09-27

    但是这相当于两个服务,这样我就调用不了原来项目里面的接口了

  • 不败少龙 2022-09-27

    恩! 命令行执行是有这个问题

  • 不败少龙 2022-09-27

    两个其实不影响的,都可以使用

  • chenStudy 2022-09-27

    那如果我用这种点击运行的,想调接口就只能用http请求去调用对吧

  • 不败少龙 2022-09-27

    恩! 是这样的

  • chenStudy 2022-09-28

    三Q啦

  • chenStudy 2022-09-28

    你知道自定义协议接收数据不是我想要的怎样消费掉嘛,它现在一直加在后面

chenStudy

截图

  • 不败少龙 2022-09-28

    自定义协议的话 要看手册这章https://www.workerman.net/doc/workerman/protocols/how-protocols.html 去处理黏包数据等 处理接收的数据 也是在onMessage里面去处理啊

  • chenStudy 2022-09-28

    哦哦谢谢啦

chenStudy

还想再问一下,我自己定义的协议,启动的时候报找不找这个自定义的协议是因为没有引对命名空间嘛
截图
截图

chenStudy

截图,我改了一下,我这个自定义的放在项目根目录下的,好像还是启动不起来

chenStudy

截图

年代过于久远,无法发表回答
🔝