Mysql-in PHP, you can use the pcntl_fork function to generate a process, but the official website says...

Source: Internet
Author: User
In PHP, processes can be generated through the pcntl_fork function, but the official saying that it may bring unexpected results when used in the Web service environment. I don't know if you have used it. What are the unexpected consequences? Because I want to do one thing through PHP, but I want to finish it together by starting multiple PHP processes... in PHP, processes can be generated through the pcntl_fork function, but the official saying that it may bring unexpected results when used in the Web service environment. I don't know if you have used it. What are the unexpected consequences?

Because I want to do one thing through PHP, but I want to do it together by starting multiple PHP processes, so I thought of the pcntl_fork function, but I don't know about the process, I don't know if this idea is feasible. If so, how can it be implemented?

Reply content:

In PHP, processes can be generated through the pcntl_fork function, but the official saying that it may bring unexpected results when used in the Web service environment. I don't know if you have used it. What are the unexpected consequences?

Because I want to do one thing through PHP, but I want to do it together by starting multiple PHP processes, so I thought of the pcntl_fork function, but I don't know about the process, I don't know if this idea is feasible. If so, how can it be implemented?

Some people will always criticize the problem of memory management when the PHP process is resident,:

Https://github.com/CoderKungfu/php-queue

Https://github.com/chrisboulton/php-resque

The two library models use a master process that is only responsible for fork to work with the worker process that comes out of the fork to achieve a reliable/easy-to-manage "resident", and the master process does little, the worker stops after it completes the job, so you can use it with confidence.

Sub-processes generated in apache, fastcgi, and php-fpm modes all have lifecycles, which may be killed or become zombie upon timeout.

You can use the popen function to meet your needs. I often do this.

Processes generated in this way are difficult to manage and are not officially recommended.

This method violates php's language features. a php request ends with a response, which is a life cycle.

For pcntl functions, it is recommended that you use the best command when running the cli mode of php.

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.