php8.5
Home/ Manual/ swoole / timer/ Swoole\Timer::list

Swoole\Timer::list

PHP function Edit on GitHub ✎

Get an iterator over the timers of the current process

Description

Swoole\Timer::list(): Swoole\Timer\Iterator

Returns an iterator over the IDs of the timers created from PHP in the current process. Timers created internally by Swoole are not listed. As of Swoole 4.4.0.

Return Values

Returns a Swoole\Timer\Iterator object, which extends ArrayIterator and yields the timer IDs as int values. The iterator is a snapshot taken when the method is called; it is empty when no timer exists.

Examples

Swoole\Timer::list() example

php
<?php
Swoole\Timer::tick(1000, function () {});
Swoole\Timer::after(5000, function () {});

foreach (Swoole\Timer::list() as $timer_id) {
    echo $timer_id, "\n";
    Swoole\Timer::clear($timer_id);
}
?>

The above example will output something similar to:

output
1
2

Source: reference/swoole/swoole/timer/list.xml · from the official PHP manual (php/doc-en)