Home > php教程 > php手册 > body text

PHP多进程简单实例程序

WBOY
Release: 2016-06-13 09:47:33
Original
1089 people have browsed it

多进程可以说php在这方面比起java差得太多了,下面出现好玩找到一个关于PHP多进程实例,给大家看一下。

 代码如下 复制代码

$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);
 }  
}  
?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!