<?php
$pid =pcntl_fork ();//fork is a child process that has been created, both the parent and child processes start down from the fork position, and the difference is that the fork return value is the child process number when the parent process executes, and the child process gets 0.
if ($pid ==-1) {
Die (' Create child process failed ');
Die (' failed ');
}elseif ($pid) {
Echo ' P ';
Pcntl_wait ($status);
$id =getmypid ();
echo "The parent process ID is {$id} and the child process ID is {$pid}";
echo "parentpid:{$id},childpid:{$pid}";
}elseif ($pid ==0) {
$id =getmypid ();//Returns the PID of the current process
echo "sub-process pid {$id}";
echo "childpid:{$id}";
Sleep (30);
}
?>
Above is a PHP multi-process Small instance I wrote, if you need to execute a lot of processes at the same time, in the parent process or child processes continue to use pcntl_fork (), and also do not forget to use the parent process pc_wait ($status), otherwise easily become a zombie process.
PHP Multi-Process Small instance