问下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进程了
不知道为啥会没有那些进程?
windows 系统需要单独配置一下 command 文件,根目录创建
start_for_win.bat
文件好好看下文档
www.workerman.net/windows