@@ -775,36 +775,24 @@ public function getStatus()
775
775
* Stops the process.
776
776
*
777
777
* @param int|float $timeout The timeout in seconds
778
- * @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL
778
+ * @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
779
779
*
780
780
* @return int The exit-code of the process
781
- *
782
- * @throws RuntimeException if the process got signaled
783
781
*/
784
782
public function stop ($ timeout = 10 , $ signal = null )
785
783
{
786
784
$ timeoutMicro = microtime (true ) + $ timeout ;
787
785
if ($ this ->isRunning ()) {
788
- if ('\\' === DIRECTORY_SEPARATOR && !$ this ->isSigchildEnabled ()) {
789
- exec (sprintf ('taskkill /F /T /PID %d 2>&1 ' , $ this ->getPid ()), $ output , $ exitCode );
790
- if ($ exitCode > 0 ) {
791
- throw new RuntimeException ('Unable to kill the process ' );
792
- }
793
- }
794
786
// given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
795
787
$ this ->doSignal (15 , false );
796
788
do {
797
789
usleep (1000 );
798
790
} while ($ this ->isRunning () && microtime (true ) < $ timeoutMicro );
799
791
800
792
if ($ this ->isRunning () && !$ this ->isSigchildEnabled ()) {
801
- if (null !== $ signal || defined ('SIGKILL ' )) {
802
- // avoid exception here :
803
- // process is supposed to be running, but it might have stop
804
- // just after this line.
805
- // in any case, let's silently discard the error, we can not do anything
806
- $ this ->doSignal ($ signal ?: SIGKILL , false );
807
- }
793
+ // Avoid exception here: process is supposed to be running, but it might have stopped just
794
+ // after this line. In any case, let's silently discard the error, we cannot do anything.
795
+ $ this ->doSignal ($ signal ?: 9 , false );
808
796
}
809
797
}
810
798
@@ -1473,7 +1461,18 @@ private function doSignal($signal, $throwException)
1473
1461
return false ;
1474
1462
}
1475
1463
1476
- if (true !== @proc_terminate ($ this ->process , $ signal )) {
1464
+ if ('\\' === DIRECTORY_SEPARATOR ) {
1465
+ exec (sprintf ('taskkill /F /T /PID %d 2>&1 ' , $ this ->getPid ()), $ output , $ exitCode );
1466
+ if ($ exitCode ) {
1467
+ if ($ throwException ) {
1468
+ throw new RuntimeException (sprintf ('Unable to kill the process (%s). ' , implode (' ' , $ output )));
1469
+ }
1470
+
1471
+ return false ;
1472
+ }
1473
+ }
1474
+
1475
+ if (true !== @proc_terminate ($ this ->process , $ signal ) && '\\' !== DIRECTORY_SEPARATOR ) {
1477
1476
if ($ throwException ) {
1478
1477
throw new RuntimeException (sprintf ('Error while sending signal `%s`. ' , $ signal ));
1479
1478
}
0 commit comments