workerman异步,为什么会有等待?

小冷
  • 1
新手上路,请多包涵

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在调用的时候,也不应该用等待啊

回复
阅读 156
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏