@@ -306,15 +306,17 @@ public function start($callback = null)
306
306
$ w = $ writePipes ;
307
307
$ e = null ;
308
308
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
+ }
312
314
break ;
313
315
}
314
- if ($ n === 0 ) {
315
- proc_terminate ($ this ->process );
316
316
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 ;
318
320
}
319
321
320
322
if ($ w ) {
@@ -404,10 +406,9 @@ public function wait($callback = null)
404
406
405
407
// let's have a look if something changed in streams
406
408
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 ()) {
411
412
$ this ->pipes = array ();
412
413
}
413
414
@@ -1140,4 +1141,17 @@ private function processFileHandles($callback, $closeEmptyHandles = false)
1140
1141
}
1141
1142
}
1142
1143
}
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
+ }
1143
1157
}
0 commit comments