phpsocket.io 中的 web-msg-sender 的服务无法启动

smallnews

环境

宝塔 和 docker
php 版本 7.4 和 8.0

问题描述

在 windows 本机上启动时 php7.4 和 8.0 均正常的,web-msg-sender 9191 端口可正常启动,连接

但是在linux 和 docker 容器中均不能启动,

问题补充

在启动了之后,查看端口,9191 端口是被启动了的,但是命令行中一直在报错

部分代码如下

$io = new SocketIO($port, $context);
$io->worker->name = 'SheepChatWorker';
$io->worker->count = $worker_num;     // 启动 worker 的进程数量;
$io->debug = $debug;        // 自定义 debug

// 定义命名空间
$nsp = $io->of('/chat');
$io->on('workerStart', function () use ($io, $nsp, $inside_port) {
    $inner_http_worker = new Worker('http://0.0.0.0:' . $inside_port);
    $inner_http_worker->onMessage = function (TcpConnection $httpConnection, Request $request) use ($io, $nsp) {
    // 请求地址
    $uri = $request->uri();
    // 请求参数
    $data = $request->post();

    $chat = new Chat($io, $nsp);
    $chat->innerWorker($httpConnection, $uri, $data);
    };
    $inner_http_worker->listen();
});

报错信息

报错提示端口被占用,但是确认 linux 和 docker 中都没有进程使用 9191端口

Address already in use 这个错误是一直在重复的报错,这里只截取了一个完整的错误信息

$ sudo -u www /www/server/php/74/bin/php think sheep:chat   // 自己写的 thinkphp command
Workerman[think sheep:chat] start in DEBUG mode
-------------------------------------------- WORKERMAN ---------------------------------------------
Workerman version:4.0.19          PHP version:7.4.9
--------------------------------------------- WORKERS ----------------------------------------------
proto   user            worker             listen                     processes    status
tcp     www             SheepChatWorker    socketIO://0.0.0.0:2121    2             [OK]
----------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
think\exception\ErrorException: stream_socket_server(): unable to connect to tcp://0.0.0.0:9191 (Address already in use) in /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php:2255
Stack trace:
#0 [internal function]: think\initializer\Error->appError()
#1 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(2255): stream_socket_server()
#2 /www/wwwroot/sa.test.7wpp.com/app/sheep/console/SheepChat.php(114): Workerman\Worker->listen()
#3 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(2415): app\sheep\console\SheepChat->app\sheep\console\{closure}()
#4 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(1554): Workerman\Worker->run()
#5 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(1384): Workerman\Worker::forkOneWorkerForLinux()
#6 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(1358): Workerman\Worker::forkWorkersForLinux()
#7 /www/wwwroot/sa.test.7wpp.com/vendor/workerman/workerman/Worker.php(542): Workerman\Worker::forkWorkers()
#8 /www/wwwroot/sa.test.7wpp.com/app/sheep/console/SheepChat.php(162): Workerman\Worker::runAll()
#9 /www/wwwroot/sa.test.7wpp.com/app/sheep/console/SheepChat.php(66): app\sheep\console\SheepChat->start()
#10 /www/wwwroot/sa.test.7wpp.com/vendor/topthink/framework/src/think/console/Command.php(210): app\sheep\console\SheepChat->execute()
#11 /www/wwwroot/sa.test.7wpp.com/vendor/topthink/framework/src/think/Console.php(655): think\console\Command->run()
#12 /www/wwwroot/sa.test.7wpp.com/vendor/topthink/framework/src/think/Console.php(314): think\Console->doRunCommand()
#13 /www/wwwroot/sa.test.7wpp.com/vendor/topthink/framework/src/think/Console.php(251): think\Console->doRun()
#14 /www/wwwroot/sa.test.7wpp.com/think(16): think\Console->run()
#15 {main}
Worker[7857] process terminated
worker[SheepChatWorker:7857] exit with status 64000

目前没有解决思路,请大佬指点一二,拜谢

2827 1 0
1个回答

six

我记得 SocketIO 不支持设置进程数量的。$io->worker->count = $worker_num; 去掉试下吧

  • smallnews 2021-09-17

    厉害了,还真是因为启动两个进程导致的,启动两个进程会导致 web msg 这个也会启动两次,然后就会提示端口被占用,不知道为啥 windows 上面居然可以启动多个进程

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