Home >Backend Development >PHP Tutorial >PHP多进程的父进程怎么不做事呢? 求问:

PHP多进程的父进程怎么不做事呢? 求问:

WBOY
WBOYOriginal
2016-06-23 13:21:351004browse

$arr=array();for($i=0;$i<10;$i++){    $pid = pcntl_fork();    if ($pid == -1) {        die('could not fork');    } else if (!$pid) {        //父进程: 为什么不做事?!        $arr[]=1;        pcntl_wait($status); //等待子进程中断,防止子进程成为僵尸进程。    } else {        $arr[]=mt_rand();    }}


上面的案例,为什么      $arr[]=1, 并没有添加到数组中  . 父进程难道不做事?


回复讨论(解决方案)

$pid = pcntl_fork();
在正常情况下,$pid 应是什么值?

Statement:
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