Quantcast
Channel: Kommentare zu: Parallel processing in PHP
Viewing all articles
Browse latest Browse all 38

Von: Indrek

$
0
0

You have done little wrong in fork example. Better example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$pids = array();
for ($i = 0; $i < 4; $i++)
{
    if ($pid = pcntl_fork())
   {
      $pids[] = $pid;
      break; // Now I'm child process and exit from loop
   }
}
// Now must wait until all children are finished
while ($pids)
{
  $pid = pcntl_wait(0);
  // remove $pid from $pids
}

Viewing all articles
Browse latest Browse all 38