首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
进程(9501端口)一段时间后会自己退出;
### 问题描述 进程(9501端口)一段时间后会自己退出; 请问是需要设置max_coroutine嘛;另外ws->close协程会自动退出嘛新版文档;没用具体写 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.5.1 php:7.4 ### 相关代码 ```php function getObjectId(\Swoole\Http\Response $response) { if (PHP_VERSION_ID < 70200) { $id = spl_object_hash($response); } else { $id = spl_object_id($response); } return $id; } Co::set([ 'hook_flags'=> SWOOLE_HOOK_ALL, 'heartbeat_check_interval' => 3 ]); Co\run(function (){ $server = new Co\Http\Server("0.0.0.0", 9501, false); $chan = new Swoole\Coroutine\Channel(10); $server->handle('/', function ($request, $ws) use ($chan) { $ws->upgrade(); global $wsObjects; $wsObjects[getObjectId($ws)] = $ws; $i = 0; while (true) { $frame = $ws->recv(); $pingFrame = new Swoole\WebSocket\Frame; $pingFrame->opcode = WEBSOCKET_OPCODE_PONG; $ws->push($pingFrame); if ($frame === '' or $frame->data === '') { $ws->close(); break; } else if ($frame === false) { echo "error : " . swoole_last_error() . "\n"; break; } else { if ($frame->data == 'close') { $ws->close(); return; } $ws->push("fd: ".$frame->fd. "this is test message:".rand(1000, 9999), 2); } } }); $server->start(); }); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么?
发布于5年前 · 2 次浏览 · 来自
提问
highkick
### 问题描述 进程(9501端口)一段时间后会自己退出; 请问是需要设置max_coroutine嘛;另外ws->close协程会自动退出嘛新版文档;没用具体写 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.5.1 php:7.4 ### 相关代码 ```php function getObjectId(\Swoole\Http\Response $response) { if (PHP_VERSION_ID < 70200) { $id = spl_object_hash($response); } else { $id = spl_object_id($response); } return $id; } Co::set([ 'hook_flags'=> SWOOLE_HOOK_ALL, 'heartbeat_check_interval' => 3 ]); Co\run(function (){ $server = new Co\Http\Server("0.0.0.0", 9501, false); $chan = new Swoole\Coroutine\Channel(10); $server->handle('/', function ($request, $ws) use ($chan) { $ws->upgrade(); global $wsObjects; $wsObjects[getObjectId($ws)] = $ws; $i = 0; while (true) { $frame = $ws->recv(); $pingFrame = new Swoole\WebSocket\Frame; $pingFrame->opcode = WEBSOCKET_OPCODE_PONG; $ws->push($pingFrame); if ($frame === '' or $frame->data === '') { $ws->close(); break; } else if ($frame === false) { echo "error : " . swoole_last_error() . "\n"; break; } else { if ($frame->data == 'close') { $ws->close(); return; } $ws->push("fd: ".$frame->fd. "this is test message:".rand(1000, 9999), 2); } } }); $server->start(); }); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么?
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-10-17
鲁飞
close只是关闭这个连接。示例代码close掉请求的这个协程就结束了
赞
0
回复
2020-10-17
highkick
回复
鲁飞
请问 这边需要添加 max_coroutine 来控制协程数量嘛
赞
0
回复
2020-10-19
鲁飞
回复
highkick
超过了默认你就设置大些...
赞
0
回复