Fork and zombies

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

 



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.  I could rewrite this to instead call fork multiple times, then
wait on all of them to return, but as my system is currently architected,
the easiest way would be to fire and forget for this script.  Does anyone
have any ideas on the best way to do it?  The other way I've done this is to
use exec("php foo.php") and redirecting stdout and stderr to /dev/null.

Waynn

[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