Home  >  Article  >  PHP Framework  >  How to apply swoole's timer

How to apply swoole's timer

(*-*)浩
(*-*)浩Original
2019-12-06 13:50:473174browse

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!

Statement:
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