We usually use PHP on the Linux to perform timed tasks, such as php -f xxx.php , sometimes need to have a PHP parent process, and then open a number of PHP sub-process to do the same thing ...
If the parent process is notified when one of the child processes ends or there is a problem, the parent process can do something, such as shutting down other running processes and so on ....
Want to know how we are doing or dealing with this kind of problem?
Reply content:
We usually use PHP on the Linux to perform timed tasks, such as php -f xxx.php , sometimes need to have a PHP parent process, and then open a number of PHP sub-process to do the same thing ...
If the parent process is notified when one of the child processes ends or there is a problem, the parent process can do something, such as shutting down other running processes and so on ....
Want to know how we are doing or dealing with this kind of problem?
I generally use PHP daemon to do, a process as a parent process has been running (may be a while + sleep), the parent process to determine the time to fork one/more sub-process to handle the business, the parent process to listen to the child process exit signal, the child process after the execution of the business has exited, The parent process is then detected until all child processes have exited.
One principle is that the parent process is as simple as possible and does not handle business logic to ensure the stability of the parent process. Sub-processes to process the business, even if the presence of Fataerr does not cause all processes to exit.
There is also a tip: the signal can be overwritten, that is, when two child processes exit, the parent process may receive only one signal, when the parent process should use a while loop to handle the child process exit event
http://cn2.php.net/manual/zh/function.pcntl-waitpid.php
PHP manuals are also very valuable to learn
The main meeting? I use the next pcntl this method, it seems to capture the state of the child process when the parent process will be blocked, but PHP since 5.3 to support multi-threading
Cooking with chopsticks do not know what is the feeling?