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.