@@ -647,36 +647,24 @@ public function getStatus()
647
647
* Stops the process.
648
648
*
649
649
* @param int|float $timeout The timeout in seconds
650
- * @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL
650
+ * @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
651
651
*
652
652
* @return int The exit-code of the process
653
- *
654
- * @throws RuntimeException if the process got signaled
655
653
*/
656
654
public function stop ($ timeout = 10 , $ signal = null )
657
655
{
658
656
$ timeoutMicro = microtime (true ) + $ timeout ;
659
657
if ($ this ->isRunning ()) {
660
- if ('\\' === DIRECTORY_SEPARATOR && !$ this ->isSigchildEnabled ()) {
661
- exec (sprintf ('taskkill /F /T /PID %d 2>&1 ' , $ this ->getPid ()), $ output , $ exitCode );
662
- if ($ exitCode > 0 ) {
663
- throw new RuntimeException ('Unable to kill the process ' );
664
- }
665
- }
666
658
// given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
667
659
$ this ->doSignal (15 , false );
668
660
do {
669
661
usleep (1000 );
670
662
} while ($ this ->isRunning () && microtime (true ) < $ timeoutMicro );
671
663
672
664
if ($ this ->isRunning () && !$ this ->isSigchildEnabled ()) {
673
- if (null !== $ signal || defined ('SIGKILL ' )) {
674
- // avoid exception here :
675
- // process is supposed to be running, but it might have stop
676
- // just after this line.
677
- // in any case, let's silently discard the error, we can not do anything
678
- $ this ->doSignal ($ signal ?: SIGKILL , false );
679
- }
665
+ // Avoid exception here: process is supposed to be running, but it might have stopped just
666
+ // after this line. In any case, let's silently discard the error, we cannot do anything.
667
+ $ this ->doSignal ($ signal ?: 9 , false );
680
668
}
681
669
}
682
670
@@ -1200,7 +1188,18 @@ private function doSignal($signal, $throwException)
1200
1188
return false ;
1201
1189
}
1202
1190
1203
- if (true !== @proc_terminate ($ this ->process , $ signal )) {
1191
+ if ('\\' === DIRECTORY_SEPARATOR ) {
1192
+ exec (sprintf ('taskkill /F /T /PID %d 2>&1 ' , $ this ->getPid ()), $ output , $ exitCode );
1193
+ if ($ exitCode ) {
1194
+ if ($ throwException ) {
1195
+ throw new RuntimeException (sprintf ('Unable to kill the process (%s). ' , implode (' ' , $ output )));
1196
+ }
1197
+
1198
+ return false ;
1199
+ }
1200
+ }
1201
+
1202
+ if (true !== @proc_terminate ($ this ->process , $ signal ) && '\\' !== DIRECTORY_SEPARATOR ) {
1204
1203
if ($ throwException ) {
1205
1204
throw new RuntimeException (sprintf ('Error while sending signal `%s`. ' , $ signal ));
1206
1205
}
0 commit comments