首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
open_eof_check 配置为何无效?[已解决]
{{{php $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); $client->set(array( 'open_eof_check' => true, 'open_eof_split' => true, //打开EOF_SPLIT检测,就解决了 'package_eof' => "\r\n", )); //注册连接成功回调 $client->on("connect", function($cli) { $cli->send("hello world\r\n"); }); $timeout_heater = time(); $tick_heater = Swoole\Timer::tick(1000 * 3, function () use ($client,&$timeout_heater,&$tick_heater) { $client->send("ping\r\n"); if((time() - $timeout_heater) >10){ echo "心跳检测超时"; $client->close(); Swoole\Timer::clear($tick_heater); } }); //注册数据接收回调 $client->on("receive", function($cli, $data) use(&$timeout_heater){ $data = trim($data); if($data == "pong"){ $timeout_heater = time(); }else{ var_dump($data); } }); Swoole\Timer::tick(1000 * 2, function () use (&$client) { $client->send("hello2\r\n"); }); Swoole\Timer::tick(1000 * 2, function () use (&$client) { $client->send("hello1\r\n"); }); }}} //运行结果 string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1" string(20) "Server: hello1 pong" string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1" string(20) "Server: hello1 pong" string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1"
发布于5年前 · 5 次浏览 · 来自
提问
伊
伊耆ぐ赤熛怒
{{{php $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); $client->set(array( 'open_eof_check' => true, 'open_eof_split' => true, //打开EOF_SPLIT检测,就解决了 'package_eof' => "\r\n", )); //注册连接成功回调 $client->on("connect", function($cli) { $cli->send("hello world\r\n"); }); $timeout_heater = time(); $tick_heater = Swoole\Timer::tick(1000 * 3, function () use ($client,&$timeout_heater,&$tick_heater) { $client->send("ping\r\n"); if((time() - $timeout_heater) >10){ echo "心跳检测超时"; $client->close(); Swoole\Timer::clear($tick_heater); } }); //注册数据接收回调 $client->on("receive", function($cli, $data) use(&$timeout_heater){ $data = trim($data); if($data == "pong"){ $timeout_heater = time(); }else{ var_dump($data); } }); Swoole\Timer::tick(1000 * 2, function () use (&$client) { $client->send("hello2\r\n"); }); Swoole\Timer::tick(1000 * 2, function () use (&$client) { $client->send("hello1\r\n"); }); }}} //运行结果 string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1" string(20) "Server: hello1 pong" string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1" string(20) "Server: hello1 pong" string(14) "Server: hello2" string(30) "Server: hello2 Server: hello1" string(30) "Server: hello2 Server: hello1"
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2019-05-22
T
Too young to love
* `open_eof_check` 仅判断数据包末尾是否为`EOF` * `open_eof_split`会使用`EOF`对数据包进行切割
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- 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一直是同一个。没用使用到多进程啊。