note 62661 deleted from function.pcntl-waitpid by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:58:00 +0000 |
| Subject: | note 62661 deleted from function.pcntl-waitpid by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197247@lists.php.net to get a copy of this message | ||
Note Submitter: admin at albert dot us dot com
----
Here's a decent example of the pcntl_waitpid() call:
$i = 0;
$starttime = microtime(TRUE);
$pid_arr = array();
while ($i < intval($argv[1]))
{
$pid = pcntl_fork();
if ($pid == -1)
{
die('could not fork');
}
else
{
if ($pid) // parent
{
$pid_arr[$i] = $pid;
}
else // child
{
performSomeFunction($i+1);
}
}
$i++;
}
foreach ($pid_arr as $pid)
{
// we are the parent
pcntl_waitpid($pid, $status);
}
$elapsed = microtime(TRUE) - $starttime;
print "\n==> total elapsed: " . sprintf("%f secs.\n", $elapsed);