企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# swoole_server->tick tick定时器,可以自定义回调函数。此函数是[swoole_timer_tick](https://wiki.swoole.com/wiki/page/412.html)的别名。 > worker进程结束运行后,所有定时器都会自动销毁 > tick/after定时器不能在swoole_server->start之前使用 在onReceive中使用 -------------- ```php function onReceive($server, $fd, $from_id, $data) { $server->tick(1000, function() use ($server, $fd) { $server->send($fd, "hello world"); }); } ``` 在onWorkerStart中使用 -------------- * 低于`1.8.0`版本task进程不能使用`tick/after`定时器,所以需要使用$serv->taskworker进行判断 ```php function onWorkerStart(swoole_server $serv, $worker_id) { if (!$serv->taskworker) { $serv->tick(1000, function ($id) { var_dump($id); }); } else { //task $serv->tick(1000); } } ```