异步任务返回结果问题

defeatlr

在GW中执行异步任务,任务开了个worker在onMessage中返回connection->send('ok');
然后我在GW中获得异步结果直接打印var_dump($task_result);
会出现下面的情况
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "string(2) "string(2) "okok"
ok"
"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "string(2) "okok"
"
string(2) "string(2) "ok"
ok"
string(2) "string(2) "okok"
"
string(2) "ok"
string(2) "ok"
string(2) "ok"

测试是在本机开了一个worker做客户端发的请求

2492 1 0
1个回答

songl

这个问题我碰到过,因为没加通讯协议分包导致的,直接用tcp会粘包的。
GW 和 任务worker之间要有个通讯协议,我用的text协议就好了。类似这样的,
worker的代码
$task = new Worker('text://0.0.0.0:6006');

GW调用的时候
$con = new AsyncTcpConnection('text://ip:6006');

  • defeatlr 2017-11-21

    我是用的text协议的 GW和worker都用的text协议了

年代过于久远,无法发表回答
🔝