[Process] Disable exception on stream_select timeout

This commit is contained in:
Romain Neutron 2013-06-13 15:45:36 +02:00
parent ed3bcb047a
commit c0da3ae445
1 changed files with 24 additions and 10 deletions

View File

@ -306,15 +306,17 @@ class Process
$w = $writePipes; $w = $writePipes;
$e = null; $e = null;
$n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6)); if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) {
// if a system call has been interrupted, forget about it, let's try again
if (false === $n) { if ($this->hasSystemCallBeenInterrupted()) {
continue;
}
break; break;
} }
if ($n === 0) {
proc_terminate($this->process);
throw new RuntimeException('The process timed out.'); // nothing has changed, let's wait until the process is ready
if (0 === $n) {
continue;
} }
if ($w) { if ($w) {
@ -404,10 +406,9 @@ class Process
// let's have a look if something changed in streams // let's have a look if something changed in streams
if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) { if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) {
$lastError = error_get_last(); // if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occured, let's reset pipes
// stream_select returns false when the `select` system call is interrupted by an incoming signal if (!$this->hasSystemCallBeenInterrupted()) {
if (isset($lastError['message']) && false === stripos($lastError['message'], 'interrupted system call')) {
$this->pipes = array(); $this->pipes = array();
} }
@ -1140,4 +1141,17 @@ class Process
} }
} }
} }
/**
* Returns true if a system call has been interrupted.
*
* @return Boolean
*/
private function hasSystemCallBeenInterrupted()
{
$lastError = error_get_last();
// stream_select returns false when the `select` system call is interrupted by an incoming signal
return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
}
} }