Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0da3ae

Browse files
committed
[Process] Disable exception on stream_select timeout
1 parent ed3bcb0 commit c0da3ae

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ public function start($callback = null)
306306
$w = $writePipes;
307307
$e = null;
308308

309-
$n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6));
310-
311-
if (false === $n) {
309+
if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) {
310+
// if a system call has been interrupted, forget about it, let's try again
311+
if ($this->hasSystemCallBeenInterrupted()) {
312+
continue;
313+
}
312314
break;
313315
}
314-
if ($n === 0) {
315-
proc_terminate($this->process);
316316

317-
throw new RuntimeException('The process timed out.');
317+
// nothing has changed, let's wait until the process is ready
318+
if (0 === $n) {
319+
continue;
318320
}
319321

320322
if ($w) {
@@ -404,10 +406,9 @@ public function wait($callback = null)
404406

405407
// let's have a look if something changed in streams
406408
if (false === $n = @stream_select($r, $w, $e, 0, ceil(static::TIMEOUT_PRECISION * 1E6))) {
407-
$lastError = error_get_last();
408-
409-
// stream_select returns false when the `select` system call is interrupted by an incoming signal
410-
if (isset($lastError['message']) && false === stripos($lastError['message'], 'interrupted system call')) {
409+
// if a system call has been interrupted, forget about it, let's try again
410+
// otherwise, an error occured, let's reset pipes
411+
if (!$this->hasSystemCallBeenInterrupted()) {
411412
$this->pipes = array();
412413
}
413414

@@ -1140,4 +1141,17 @@ private function processFileHandles($callback, $closeEmptyHandles = false)
11401141
}
11411142
}
11421143
}
1144+
1145+
/**
1146+
* Returns true if a system call has been interrupted.
1147+
*
1148+
* @return Boolean
1149+
*/
1150+
private function hasSystemCallBeenInterrupted()
1151+
{
1152+
$lastError = error_get_last();
1153+
1154+
// stream_select returns false when the `select` system call is interrupted by an incoming signal
1155+
return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
1156+
}
11431157
}

0 commit comments

Comments
 (0)