Home > PHP Framework > Swoole > How to set timer in swoole

How to set timer in swoole

(*-*)浩
Release: 2019-12-06 09:50:46
Original
2623 people have browsed it

How to set timer in swoole

Set timer

swoole provides JavaScript-like setInterval/setTimeout asynchronous high-precision timer with millisecond-level granularity.

It is also very simple to use. (Recommended learning: swoole video tutorial)

Program code

//每隔2000ms触发一次
swoole_timer_tick(2000, function ($timer_id) {
    echo "tick-2000ms\n";
});
//3000ms后执行此函数
swoole_timer_after(3000, function () {
    echo "after 3000ms.\n";
});
Copy after login

The swoole_timer_tick function is equivalent to setInterval and is continuously triggered

The swoole_timer_after function is equivalent to setTimeout, which is only triggered once at the agreed time.

The swoole_timer_tick and swoole_timer_after functions will return an integer, indicating the ID of the timer.

You can use swoole_timer_clear to clear this timing. The parameter is the timer ID

The above is the detailed content of How to set timer in swoole. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template