问下laravel使用gateway,为啥我进程启动不起来呢?

情况是这样的,我这边项目上要用下websocket,然后我选择在laravel上安装gateway包,然后照着网上说的测试下看看

我先是composer 安装 composer require workerman/gateway-worker
然后创建一个command
php artisan make:command GatewayWorkerServer
然后 GatewayWorkerServer.php 文件内容如下

<?php

namespace App\Console\Commands;

use App\Http\Controllers\Admin\EventsController;
use Illuminate\Console\Command;
use GatewayWorker\BusinessWorker;
use Workerman\Worker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;

class GatewayWorkerServer extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'gateway-worker:server {action} {--daemon}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'test gateway-worker server';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        global $argv;

        if (!in_array($action = $this->argument('action'), ['start', 'stop', 'restart'])) {
            $this->error('Error Arguments');
            exit;
        }

        $argv[0] = 'gateway-worker:server';
        $argv[1] = $action;
        $argv[2] = $this->option('daemon') ? '-d' : '';

        $this->start();
    }

    private function start()
    {
        $this->startRegister();
        $this->startGateWay();
        $this->startBusinessWorker();
        if(!defined('GLOBAL_START'))
        {
            Worker::runAll();
        }
    }

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

    private function startGateWay()
    {
        $gateway = new Gateway("websocket://0.0.0.0:2346");
        $gateway->name                 = 'Gateway';
        $gateway->count                = 1;
        $gateway->lanIp                = '127.0.0.1';
        $gateway->startPort            = 2300;
        $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');
    }
}

然后我执行command命令:php artisan gateway-worker:server start

-------------------- WORKERMAN -------------------
Workerman version:4.1.15          PHP version:7.4.3
------------------- WORKERS ----------------------
worker             listen          processes   status

后面就没有BusinessWorker 和GateWay进程了
不知道为啥会没有那些进程?

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

windows 系统需要单独配置一下 command 文件,根目录创建 start_for_win.bat 文件

start /b php artisan workerman single --start=register
start /b php artisan workerman single --start=gateway
start /b php artisan workerman single --start=worker
pause

好好看下文档

www.workerman.net/windows

1个月前 评论
donggan (楼主) 1个月前
xiucai 1个月前
MArtian (作者) 1个月前
MArtian (作者) 1个月前
donggan (楼主) 1个月前
donggan (楼主) 1个月前
讨论数量: 13

windows系统么?怎么感觉跟之前的问题雷同

1个月前 评论
donggan (楼主) 1个月前
donggan (楼主) 1个月前
codeSeele (作者) 1个月前

我测试了下为啥在windows上面--d没什么用呢?

1个月前 评论

windows 系统需要单独配置一下 command 文件,根目录创建 start_for_win.bat 文件

start /b php artisan workerman single --start=register
start /b php artisan workerman single --start=gateway
start /b php artisan workerman single --start=worker
pause

好好看下文档

www.workerman.net/windows

1个月前 评论
donggan (楼主) 1个月前
xiucai 1个月前
MArtian (作者) 1个月前
MArtian (作者) 1个月前
donggan (楼主) 1个月前
donggan (楼主) 1个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!