Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Timer::clear(int $timerId)\:\ bool
The ID of the Timer to clear
if success, it returns true
if it fails false
will be returned
Clear a Timer by passing its ID. When creating a timer with tick
or after
it will return its timer ID, you can use this to clear/stop the timer from running.
Note: When using
Swoole\Timer::clear
it can only be used to clear timers from the current process space.
<?php
$count = 0;
function run($timerId, $param1, $param2) use(&$count)
{
$count++;
var_dump($count);
if($count >= 10)
{
Swoole\Timer->clear($timerId);
}
}
Swoole\Timer->tick(1000, "run",["param1", "param2"]);