The use of millisecond timer in spool


Interval timer,tickThe timer will continue to fire until clear() is called.

$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");

One time timer, which will be destroyed automatically after execution.

$str = "Swoole";
$timer = Swoole\Timer::after(1000, function() use ($str) {
    echo "Hello, $str\n";

Using timersIDTo delete the timer.