Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\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
OpenSwoole\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)
{
OpenSwoole\Timer->clear($timerId);
}
}
OpenSwoole\Timer->tick(1000, "run",["param1", "param2"]);