Home > PHP Framework > Swoole > body text

How to apply swoole's timer

(*-*)浩
Release: 2019-12-06 13:50:47
Original
3115 people have browsed it

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");
    });
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!