首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
send后,recv结果是其他请求的数据
### 问题描述 最近遇到几次 send后,recv结果是其他请求的数据 php:7.3.16 swoole:4.4.17 Red Hat 4.8.5 ### 相关代码 ```php //createClient方法开始===start function createClient(){ // 同步处理. if(!$this->client || $this->client->isConnected()){ $this->client = new \swoole\client(SWOOLE_SOCK_TCP | SWOOLE_KEEP); // 配置 $this->client->set(array( 'open_eof_split' => true, 'package_eof' => $this->packageEof, 'package_max_length' => 5 * 1024 *1024, )); if (!$this->client->connect($this->config['ip'], $this->config['port'], $this->outTime)) { throw new \Exception(' KClient 链接创建失败,ip'.$this->config['ip'].'端口号'.$this->config['port']); } } return $this->client; } //createClient方法结束====end // 同步发送接收. $client = $this->createClient();// $sendData = $this->getSendData($param,$method); $client->send($sendData); $jsonStr = $client->recv(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 例如:本来是取专家数据,结果返回的是用户数据,是返回了其他请求的数据
发布于5年前 · 1 次浏览 · 来自
提问
persy
### 问题描述 最近遇到几次 send后,recv结果是其他请求的数据 php:7.3.16 swoole:4.4.17 Red Hat 4.8.5 ### 相关代码 ```php //createClient方法开始===start function createClient(){ // 同步处理. if(!$this->client || $this->client->isConnected()){ $this->client = new \swoole\client(SWOOLE_SOCK_TCP | SWOOLE_KEEP); // 配置 $this->client->set(array( 'open_eof_split' => true, 'package_eof' => $this->packageEof, 'package_max_length' => 5 * 1024 *1024, )); if (!$this->client->connect($this->config['ip'], $this->config['port'], $this->outTime)) { throw new \Exception(' KClient 链接创建失败,ip'.$this->config['ip'].'端口号'.$this->config['port']); } } return $this->client; } //createClient方法结束====end // 同步发送接收. $client = $this->createClient();// $sendData = $this->getSendData($param,$method); $client->send($sendData); $jsonStr = $client->recv(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 例如:本来是取专家数据,结果返回的是用户数据,是返回了其他请求的数据
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2021-01-12
Rango
如果你使用了`SWOOLE_KEEP`,底层会保持上连接,这会出现连接复用,你需要实现`RequestID`的机制,服务端返回的内容要加上这个`RequestID`,匹配对应的请求。
赞
1
回复
2021-01-14
persy
回复
Rango
多谢多谢,有相关的参考文档吗
赞
0
回复
2021-01-08
鲁飞
这个不应该检查你自己的代码逻辑吗?数据是哪来的
赞
0
回复
2021-01-12
persy
回复
鲁飞
$client->send($sendData); $jsonStr = $client->recv(); 会不会因为 fd 重复导致接收数据错乱?
赞
0
回复
2021-01-12
persy
回复
鲁飞
并发量特别大的时候,1天内有1次或2次会出现这种情况,并发量小的时候不出现,所以一直在追fg的值,感觉像是长链接串了
赞
0
回复
2021-01-11
lg430
tcpdump抓一下啊
赞
0
回复