Multi-process It can be said that PHP is much worse than Java in this aspect. Here is a fun example of PHP multi-process for everyone to take a look at.
代码如下 | 复制代码 |
$cmds=array(a,b,c,d); foreach($cmds as $cmd){ $pid = pcntl_fork(); if($pid == -1) { exit("pid fork error"); } if($pid) { //主进程段,控制子进程数量 static $max = 0; $max++; if($max >= 5) { pcntl_wait($status); //阻塞父进程,直到子进程结束 $max--; } } else { //子进程执行命令 $pid = posix_getpid(); echo "$pid----$cmdnn"; exit(0); } } ?> |