首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
发现一个奇怪的问题
背景是这样的:有多个client发送数据,server负责接收,然后写入数据库。为了提高效率,我把数据拼接到一起再写入数据库。测试的拼接是这样写的,其中$data最后以“\n”结束,我没有去掉它,所以是一行一行的: {{{ public function onReceive( swoole_server $serv, $fd, $from_id, $data ) { $this->sql = $this->sql . '|' .$data; } }}} 然后使用定时器定时输出 $this->sql 结果输出后,发现会出一个奇怪的状况:正常情况应该是每一行数据前面都会有“|”,但是输出的结果是这样的: {{{ 3, 0.26,0.46,0.20,68,0.00 |3, 0.62,0.34,-0.28,69,0.00 |3, 0.53,0.50,-0.03,70,0.00 3, 0.07,0.21,0.14,71,0.00 |3, 0.41,0.02,-0.39,72,0.00 |3, 0.24,0.11,-0.13,73,0.00 3, 0.72,0.57,-0.14,74,0.00 |3, 0.04,0.03,-0.02,75,0.00 |3, 0.08,0.08,0.00,76,0.00 3, 0.72,0.03,-0.69,77,0.00 |3, 0.67,0.14,-0.53,78,0.00 |3, 0.68,0.09,-0.59,79,0.00 3, 0.80,0.33,-0.47,80,0.00 }}} 请问这该如何解决呢?
发布于7年前 · 0 次浏览 · 来自
提问
↑
↑¢无怨无悔
背景是这样的:有多个client发送数据,server负责接收,然后写入数据库。为了提高效率,我把数据拼接到一起再写入数据库。测试的拼接是这样写的,其中$data最后以“\n”结束,我没有去掉它,所以是一行一行的: {{{ public function onReceive( swoole_server $serv, $fd, $from_id, $data ) { $this->sql = $this->sql . '|' .$data; } }}} 然后使用定时器定时输出 $this->sql 结果输出后,发现会出一个奇怪的状况:正常情况应该是每一行数据前面都会有“|”,但是输出的结果是这样的: {{{ 3, 0.26,0.46,0.20,68,0.00 |3, 0.62,0.34,-0.28,69,0.00 |3, 0.53,0.50,-0.03,70,0.00 3, 0.07,0.21,0.14,71,0.00 |3, 0.41,0.02,-0.39,72,0.00 |3, 0.24,0.11,-0.13,73,0.00 3, 0.72,0.57,-0.14,74,0.00 |3, 0.04,0.03,-0.02,75,0.00 |3, 0.08,0.08,0.00,76,0.00 3, 0.72,0.03,-0.69,77,0.00 |3, 0.67,0.14,-0.53,78,0.00 |3, 0.68,0.09,-0.59,79,0.00 3, 0.80,0.33,-0.47,80,0.00 }}} 请问这该如何解决呢?
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2017-01-07
淡BAN的茶香
因为TCP通信是流式的,在接收1个大数据包时,可能会被拆分成多个数据包发送。多次Send底层也可能会合并成一次进行发送。 http://rango.swoole.com/archives/464
赞
0
回复
2017-01-07
貓
貓朵朵。
谢谢您的回答,事实上我注意到了这个问题,也配置了参数: {{{ $this->serv->set(array( 'worker_num' => 8, 'daemonize' => false, 'max_request' => 10000, 'dispatch_mode' => 2, 'debug_mode'=> 1 ,
赞
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一直是同一个。没用使用到多进程啊。