问下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进程了
不知道为啥会没有那些进程?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

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个月前

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