diff --git a/src/Spork/Fork.php b/src/Spork/Fork.php index e46abdf..b3f31f3 100644 --- a/src/Spork/Fork.php +++ b/src/Spork/Fork.php @@ -53,8 +53,14 @@ public function wait($hang = true) return $this; } - if (-1 === $pid = pcntl_waitpid($this->pid, $status, ($hang ? 0 : WNOHANG) | WUNTRACED)) { - throw new ProcessControlException('Error while waiting for process '.$this->pid); + $retriesLimit = 100; + $retriesCounter = 0; + while (-1 === $pid = pcntl_waitpid($this->pid, $status, ($hang ? 0 : WNOHANG) | WUNTRACED)) { + if ($retriesCounter > $retriesLimit) { + throw new ProcessControlException('Error while waiting for process '.$this->pid); + } + ++$retriesCounter; + usleep(5000); } if ($this->pid === $pid) {