Home>Article>PHP Framework> The timer in workerman does not take effect

The timer in workerman does not take effect

王林
王林 Original
2019-12-13 09:51:14 2704browse

The timer in workerman does not take effect

The question leads to:

Put a \Workerman\Lib\Timer in start_gateway.php and execute it every two seconds. Each execution first records a piece of text to text file.

There is no problem when running as php start.php start, but when running as php start.php start -d, it seems that the timer is not running.

start_gateway.php code is as follows

The timer in workerman does not take effect

The timer in workerman does not take effect

The timer in workerman does not take effect

##Problem solution:

Business logic must be run in the onXXX callback (emphasized in the manual). In other words, the timer cannot run before

Worker::runAll();is executed.

Because the code run before Worker::runAll(); is executed belongs to the main process, the main process cannot have business code, and the business code of the main process will be inherited by the child process, resulting in inconsistent with the expected results.

In the above example, you can put the timer in onWorkerStart to run. It is recommended to put it in the $businessworker->onWorkerStart callback in start_businessworker.php.

Recommended related articles and tutorials:

workerman tutorial

The above is the detailed content of The timer in workerman does not take effect. 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