|
The Swoole\Timer classIntroductionMillisecond precision timer. The underlying implementation is based on epoll_wait and setitimer, using a min-heap data structure that supports adding a large number of timers. In synchronous I/O processes, such as the Manager and TaskWorker processes, it is implemented using setitimer and signals. In asynchronous I/O processes, it is implemented using the timeout of epoll_wait/kevent/poll/select.
The underlying system does not support timers with a delay of Timer Correction: The execution time of the timer callback function does not affect the timing of the next timer execution. For example, setting a tick timer of 10ms after 0.002s, the first callback will be executed at 0.012s, if the callback function takes 5ms to execute, the next timer will still trigger at 0.022s, not at 0.027s. However, if the execution time of the timer callback function is too long, even covering the time of the next timer execution, the underlying system will perform time correction, discarding the expired behavior and triggering the timer callback at the next available time. For example, if the callback function at 0.012s takes 15ms to execute, causing the timer at 0.022s to be delayed, the timer callback will be triggered again at 0.032s. By default, when a timer is triggered, a coroutine is automatically created to execute the callback function. This can be disabled with swoole_async_set. Warning
Timer only works within the current process space. Warning
Timer is purely asynchronous and incompatible with synchronous I/O functions. Warning
Timer execution may experience minor timing deviations. Class synopsisSwoole\Timer
class Swoole\Timer
{
/* Methods */
public static intfalse after(int
$ms, callable $callback, mixed ...$params)public static bool clear(int
$timer_id)public static bool clearAll()
public static bool exists(int
$timer_id)public static arraynull info(int
$timer_id)public static Swoole\Timer\Iterator list()
public static void set(array
$settings)public static array stats()
public static intfalse tick(int
}$ms, callable $callback, mixed ...$params)
|