Re: Fork and zombies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> Waynn Lue wrote:
>
> > I periodically run a script that makes a call against a remote API,
> > which
> > takes some time to return.  In an attempt to increase thoroughput, I
> > decided to investigate using pnctl_fork to spawn off multiple
> > processes to make the call, since the slowest part is the network part
> > of it (and waiting for the
> > server response).  I ended up writing a script that did this:
> >
> > $pid = pnctl_fork();
> >   if ($pid == -1) {
> >     die('could not fork');
> >   } else if ($pid) {
> >     echo "parent $pid\n";
> >     return;
> >   } else {
> >     // make API call
> >   }
> >
> > While this works, it unfortunately leaves behind a zombie process
> > every single time.
>
> You need to call pcntl_wait() or pcntl_waitpid().
>

Right, but if I do that, then the parent has to wait until the child
completes before it exits.  Is there any way to have the parent exit before
the child but prevent the zombie process for existing?

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux