$worker1 = new Worker('http://0.0.0.0:8001');
$worker1->eventLoop = Swoole::class; // 使用Swoole协程
$worker1->onMessage = function (TcpConnection $connection, Request $request) {
Coroutine::create(function () {
echo file_get_contents("http://www.example.com/event/notify");
});
$connection->send('ok');
};
不设置$worker1->eventLoop的话应该跟旧版没区别吧?
$worker1->onMessage = function (TcpConnection $connection, Request $request) {
file_get_contents("http://www.example.com/event/notify");
$connection->send('ok');
// onMessage回调是否已在协程内?包括worker的其他监听器(onWorkerStart、onWorkerStop)
}
$worker1->onMessage = function (TcpConnection $connection, Request $request) {
Coroutine::create(function () {
// 这里是在主协程下开启子协程?
echo file_get_contents("http://www.example.com/event/notify");
});
$connection->send('ok');
// onMessage内是主协程?
// 这里的执行顺序是?
// 1、$connection->send('ok');
// 2、file_get_contents("http://www.example.com/event/notify");
}
$worker1->onMessage = function (TcpConnection $connection, Request $request) {
不开启子协程的情况下,同一时刻收到多条消息时是并发触发onMessage还是要前一条消息处理完才会再次触发onMessage?
将消息处理逻辑直接运行在主协程与运行在子协程有什么区别吗?例如:优先级不同?类似js的微任务与宏任务
}
这里先感谢各位大神解答下,谢谢!!!