MySQL-About opening PHP multi-process and communication problems between them

Source: Internet
Author: User

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?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.