Home > Backend Development > PHP Tutorial > PHP multi-process simple example program_PHP tutorial

PHP multi-process simple example program_PHP tutorial

WBOY
Release: 2016-07-13 10:44:19
Original
764 people have browsed it

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);
 }  
}  
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633128.htmlTechArticleMultiple processes It can be said that php is much worse than java in this aspect. It is fun to find something about PHP below. Let me show you a multi-process example. The code is as follows Copy the code ?php $cmds=arra...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template