task_use_object

使用面向对象风格的Task回调格式。布尔值类型。设置为true时,onTask回调将变成对象模式。

$serv = new Swoole\Server('127.0.0.1', 9501);
$serv->set([
     'worker_num' => 1,
     'task_worker_num' => 3,
     'task_use_object' => true,
]);
$serv->on('receive', function (Server $serv, $fd, $tid, $data) {
     $serv->task(['fd' => $fd,]);
});
$serv->on('Task', function (Server $server, Server\Task $task) {
    $server->send($task->data['fd'], json_encode($server->stats()));

});
$serv->start();