Swoole 中毫秒定时器(Timer)的使用
2020-07-18 19:31 小伍2013 阅读(1448) 评论(0) 编辑 收藏 举报间隔定时器, tick
定时器会持续触发,直到调用 clear() 清除为止。
$timer = Swoole\Timer::tick(3000, function (int $timer_id, $param1, $param2) {
echo "timer_id #$timer_id, after 3000ms.\n";
echo "param1 is $param1, param2 is $param2.\n";
Swoole\Timer::tick(14000, function ($timer_id) {
echo "timer_id #$timer_id, after 14000ms.\n";
});
}, "A", "B");
一次性定时器,执行完成后会自动销毁。
$str = "Swoole";
$timer = Swoole\Timer::after(1000, function() use ($str) {
echo "Hello, $str\n";
});
使用定时器 ID
来删除定时器。
var_dump(Swoole\Timer::clear($timer));