Application of swote timer

Time:2020-9-27

Local version:
PHP 7.2.6、Swoole 4.3.1。
Timer

There are three main methods

swoole_ timer_ Clock controller of tick interval

swoole_ timer_ After the specified time

swoole_ timer_ Clear delete timer

Example code:
Application of swote timer

Operation results:

    tick 3000ms – 2019-04-07 21:36:56    
    tick 3000ms – 2019-04-07 21:36:59    
    tick 3000ms – 2019-04-07 21:37:02    
    after 9000ms – 2019-04-07 21:37:02

Application scenarios

1、 For example, run a business script every morning. The script includes the interface that requests other business parties or third parties. If the interface fails to respond or no data is returned, it needs to be retried.

The retrial mechanism is: Send a request again every 5 minutes, try 5 times at most, stop the task successfully within 5 times, and stop the task if 5 times still fail.

Example code:

Application of swote timer
Operation results:

On April 7, 2019, 21:40:48, during the mission… (1)
2019-04-07 21:40:48 request interface failed, try again after 5 minutes
On April 7, 2019 at 21:45:48, during the execution of the task… (2)
2019-04-07 21:45:48 request interface failed, try again after 5 minutes
On April 7, 2019 at 21:50:48, during the execution of the task… (3)
2019-04-07 21:50:48 request interface failed, try again after 5 minutes
On April 7, 2019 at 21:55:48, during the execution of the task… (4)
2019-04-07 21:55:48 request interface failed, try again after 5 minutes
On April 7, 2019 at 22:00:48, during the mission… (5)
2019-04-07 22:00:48 request interface failed, has failed 5 times, stop execution

Recommended Today

Explain idea git branch backoff specified historical version

scene When I submitted this modification to the local and remote branches, I found that there were still some changes missing in this submission, or this modification was totally wrong, but I also pushed it to the remote repository. How to go back? problem How can the content that has been submitted to the repository […]