search
HomePHP FrameworkWorkermanThe timer in workerman does not take effect

The timer in workerman does not take effect

Dec 13, 2019 am 09:51 AM
workermanfailedtimer

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool