Home > Article > PHP Framework > How to apply swoole's timer
swoole provides a JavaScript-like setInterval/setTimeout asynchronous high-precision timer with millisecond-level granularity. It's also very simple to use.
# SWOOLE provides a regular device for usage (Recommended learning: Swoole Video Tutorial ) ## r
This is how I used it. Take a look at the code.
$server->tick(1000, function() use ($server, $fd) { $server->send($fd, "hello world"); });When I started using the timer, I put it in onWorkStart for execution. In this way, I can ensure that the timer can run normally in the case of a single worker process. , but for swoole, letting it work in a single process obviously insulted its "talent", so I set work_num to 2, and then an accident happened, as shown in the figure
##
The above is the detailed content of How to apply swoole's timer. For more information, please follow other related articles on the PHP Chinese website!