首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
think-swoole 启动websocket报错invalid worker_num
### 问题描述 think-swoole 启动websocket报错invalid worker_num ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.8 php:7.4 操作系统:ubuntu-20.04.3-desktop-amd64 ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) ``` think-swoole配置代码 <?php use think\swoole\websocket\socketio\Handler; return [ 'http' => [ 'enable' => false, 'host' => '0.0.0.0', 'port' => 8000, 'worker_num' => swoole_cpu_num(), 'options' => [], ], 'websocket' => [ 'enable' => true, 'handler' => Handler::class, 'ping_interval' => 25000, 'ping_timeout' => 60000, 'room' => [ 'type' => 'table', 'table' => [ 'room_rows' => 8192, 'room_size' => 2048, 'client_rows' => 4096, 'client_size' => 2048, ], 'redis' => [ 'host' => '0.0.0.0', 'port' => 6379, 'max_active' => 12, 'max_wait_time' => 5, ], ], 'listen' => [ //'test' => \app\listener\WebsocketTest::class, ], 'subscribe' => [], ], 'rpc' => [ 'server' => [ 'enable' => false, 'host' => '0.0.0.0', 'port' => 9000, 'worker_num' => swoole_cpu_num(), 'services' => [], ], 'client' => [], ], //队列 'queue' => [ 'enable' => false, 'workers' => [], ], 'hot_update' => [ 'enable' => env('APP_DEBUG', false), 'name' => ['*.php'], 'include' => [app_path()], 'exclude' => [], ], //连接池 'pool' => [ 'db' => [ 'enable' => false, 'max_active' => 12, 'max_wait_time' => 5, ], 'cache' => [ 'enable' => false, 'max_active' => 12, 'max_wait_time' => 5, ], //自定义连接池 ], 'tables' => [], //每个worker里需要预加载以共用的实例 'concretes' => [], //重置器 'resetters' => [], //每次请求前需要清空的实例 'instances' => [], //每次请求前需要重新执行的服务 'services' => [], ]; think-swoole监听代码 <?php declare (strict_types = 1); namespace app\listener; class WebsocketTest { /** * 事件监听处理 * * @return mixed */ public function handle($event) { $ws=new \Swoole\WebSocket\Server('0.0.0.0',9506); $ws->set(array( 'worker_num'=>swoole_cpu_num(), 'task_worker_num'=>swoole_cpu_num() )); $ws->on('Open',function ($ws,$request){ echo $request->fd.'连接'.PHP_EOL; }); $ws->on('Message',function ($ws,$frame){ echo $frame->fd.'发来了'.json_encode($frame->data).PHP_EOL;; $ws->push($frame->fd,json_encode($frame->data)); }); $ws->on('Close',function ($ws,$fd){ echo $fd.'断开连接'.PHP_EOL; }); $ws->start(); } } ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待可以正常使用swoole 错误信息是 invalid worker_num
发布于2年前 · 6 次浏览 · 来自
提问
马
马吉顺
### 问题描述 think-swoole 启动websocket报错invalid worker_num ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.8 php:7.4 操作系统:ubuntu-20.04.3-desktop-amd64 ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) ``` think-swoole配置代码 <?php use think\swoole\websocket\socketio\Handler; return [ 'http' => [ 'enable' => false, 'host' => '0.0.0.0', 'port' => 8000, 'worker_num' => swoole_cpu_num(), 'options' => [], ], 'websocket' => [ 'enable' => true, 'handler' => Handler::class, 'ping_interval' => 25000, 'ping_timeout' => 60000, 'room' => [ 'type' => 'table', 'table' => [ 'room_rows' => 8192, 'room_size' => 2048, 'client_rows' => 4096, 'client_size' => 2048, ], 'redis' => [ 'host' => '0.0.0.0', 'port' => 6379, 'max_active' => 12, 'max_wait_time' => 5, ], ], 'listen' => [ //'test' => \app\listener\WebsocketTest::class, ], 'subscribe' => [], ], 'rpc' => [ 'server' => [ 'enable' => false, 'host' => '0.0.0.0', 'port' => 9000, 'worker_num' => swoole_cpu_num(), 'services' => [], ], 'client' => [], ], //队列 'queue' => [ 'enable' => false, 'workers' => [], ], 'hot_update' => [ 'enable' => env('APP_DEBUG', false), 'name' => ['*.php'], 'include' => [app_path()], 'exclude' => [], ], //连接池 'pool' => [ 'db' => [ 'enable' => false, 'max_active' => 12, 'max_wait_time' => 5, ], 'cache' => [ 'enable' => false, 'max_active' => 12, 'max_wait_time' => 5, ], //自定义连接池 ], 'tables' => [], //每个worker里需要预加载以共用的实例 'concretes' => [], //重置器 'resetters' => [], //每次请求前需要清空的实例 'instances' => [], //每次请求前需要重新执行的服务 'services' => [], ]; think-swoole监听代码 <?php declare (strict_types = 1); namespace app\listener; class WebsocketTest { /** * 事件监听处理 * * @return mixed */ public function handle($event) { $ws=new \Swoole\WebSocket\Server('0.0.0.0',9506); $ws->set(array( 'worker_num'=>swoole_cpu_num(), 'task_worker_num'=>swoole_cpu_num() )); $ws->on('Open',function ($ws,$request){ echo $request->fd.'连接'.PHP_EOL; }); $ws->on('Message',function ($ws,$frame){ echo $frame->fd.'发来了'.json_encode($frame->data).PHP_EOL;; $ws->push($frame->fd,json_encode($frame->data)); }); $ws->on('Close',function ($ws,$fd){ echo $fd.'断开连接'.PHP_EOL; }); $ws->start(); } } ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待可以正常使用swoole 错误信息是 invalid worker_num
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
还没有评论!
微信公众号
热门内容
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。