请问gatewaywork里面呢怎么指定进程开计时器呢

gatenewer
2347 3 0
3个回答

blogdaren

每个worker实例进程都有唯一的编号,即: $worker->id 属性,可以据此设置定时器,比如:

$worker->count = 4;
$worker->onWorkerStart = function($worker)
{
    //比如:只给id为0的进程设置定时器
    if($worker->id === 0)
    {
        Timer::add(1, function(){
            pprint("共启动了4个worker进程,只给0号进程设置定时器");
        });
    }
};
  • 暂无评论
gatenewer

onmessage里面的参数没看到有woker呢 怎么获取进程id呢

  • blogdaren 2018-08-10

    onMessage($connection, $data) 回调有$connection对象, 通过 $connection->woker 路由。

suunnn

$connection->woker->id

  • 暂无评论
年代过于久远,无法发表回答
🔝