pm2如何启动workerman的gateway?

情况是这样的,我这边服务器是windows系统的,想要使用gateway创建websocket连接,然后我照着网上的教程,写了一个command,然后也另外写了一个bat文件启动workerman,然后我发现bat文件启动workerman后会出现一个cmd命令行,我不想要这个cmd命令行一直开着,搞不好会有人挂掉了。
所以我想用PM2 来对进程保持,然后我用pm2,后就一直启动失败

<?php

namespace App\Console\Commands;

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

class WorkermanCommand extends Command
{

    protected $description = 'Start a Workerman server.';

    protected $signature = 'workerman
                            {action : action}
                            {--start=all : start}
                            {--d : daemon mode}';
    public function handle() {
        global $argv;
        $action = $this->argument('action');
        /**
         * 针对 Windows 一次执行,无法注册多个协议的特殊处理
         */
        if ($action === 'single') {
            $start = $this->option('start');
            if ($start === 'register') {
                $this->startRegister();
            } elseif ($start === 'gateway') {
                $this->startGateWay();
            } elseif ($start === 'worker') {
                $this->startBusinessWorker();
            }
            Worker::runAll();

            return;
        }
        /**
         * argv[0] 默认是,当前文件,可以不修改
         */
        //$argv[0] = 'wk';
        $argv[1] = $action;
        // 控制是否进入 daemon 模式
        $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           = 3;
        $worker->registerAddress = '127.0.0.1:1236';
        $worker->eventHandler    = IndexController::class;
    }
    private function startGateWay()
    {
        $gateway = new Gateway("websocket://0.0.0.0:2346");
        $gateway->name                 = 'Gateway';
        $gateway->count                = 2;
        $gateway->lanIp                = '127.0.0.1';
        $gateway->startPort            = 2300;
        $gateway->pingInterval         = 300;
        $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');
    }
}

然后bat文件是: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

然后我用pm2启动bat文件pm2 start start_for_win.bat
结果就是error了

id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ worker │ defaultN/A │ cluster │ 173201 │ stopped │ 0%0b │ test │ disabled

就问下大家这个pm2 如何启动workerman?

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

我在windows试了下,这样是可行的,相当于用pm2维护3个进程,创建一个yml文件

apps:
  - name: register 
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=register
    restart_delay: 3000
    pid_file: ./storage/app/register.pid

  - name: gateway
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=gateway
    restart_delay: 3000
    pid_file: ./storage/app/gateway.pid

  - name: worker
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=worker
    restart_delay: 3000
    pid_file: ./storage/app/worker.pid

file

1个月前 评论
donggan (楼主) 1个月前
donggan (楼主) 1个月前
讨论数量: 5
zds
start /b php artisan workerman single --start=registe

启动一个新的 cmd 窗口 执行 php artisan workerman single --start=registe 这条命令

盲猜 pm2 报的错是打开新窗口失败

1个月前 评论
donggan (楼主) 1个月前

我在windows试了下,这样是可行的,相当于用pm2维护3个进程,创建一个yml文件

apps:
  - name: register 
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=register
    restart_delay: 3000
    pid_file: ./storage/app/register.pid

  - name: gateway
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=gateway
    restart_delay: 3000
    pid_file: ./storage/app/gateway.pid

  - name: worker
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - workerman
      - single
      - --start=worker
    restart_delay: 3000
    pid_file: ./storage/app/worker.pid

file

1个月前 评论
donggan (楼主) 1个月前
donggan (楼主) 1个月前

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