間隔定時器, tick 定時器會持續觸發,直到調用 clear() 清除為止。 $timer = Swoole\Timer::tick(3000, function (int $timer_id, $param1, $param2) { echo "timer_id #$timer_id, afte ...
間隔定時器, 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));