workerman异步,为什么会有等待?
workerman服务端
$task_worker = new Worker('Text://127.0.0.1:2345');
// task进程数可以根据需要多开一些
$task_worker->count = 100;
$task_worker->name = 'server_worker';
$task_worker->onMessage = function($connection, $task_data)
{
$task_data = json_decode($task_data, true);
$type = $task_data['type'];
if($type == "check_domain"){
echo $task_data['domain'] . "\n";
if($task_data['key'] == 0){
sleep(5);
}
$connection->send("End");
}else{
$connection->send("未做任何处理");
}
};
Worker::runAll();
workerman调用
for ($x=0; $x<= 50; $x++) {
$task_data['key'] = $x;
$task_connection = new AsyncTcpConnection('Text://127.0.0.1:2345');
$task_connection->send(json_encode($task_data));
$task_connection->onMessage = function($task_connection, $task_result)use($ws_connection)
{
dump($task_result);
$task_connection->close(); // 获得结果后记得关闭异步连接
// 通知对应的websocket客户端任务完成
$ws_connection->send('task complete');
};
$task_connection->connect();
}
既然AsyncTcpConnection是异步的,即使写了sleep,curl在调用的时候,也不应该用等待啊
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论