@@ -647,36 +647,24 @@ public function getStatus()
647647 * Stops the process.
648648 *
649649 * @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)
651651 *
652652 * @return int The exit-code of the process
653- *
654- * @throws RuntimeException if the process got signaled
655653 */
656654public function stop ($ timeout =10 ,$ signal =null )
657655 {
658656$ timeoutMicro =microtime (true ) +$ timeout ;
659657if ($ 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- }
666658// given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
667659$ this ->doSignal (15 ,false );
668660do {
669661usleep (1000 );
670662 }while ($ this ->isRunning () &µtime (true ) <$ timeoutMicro );
671663
672664if ($ 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 );
680668 }
681669 }
682670
@@ -1200,7 +1188,18 @@ private function doSignal($signal, $throwException)
12001188return false ;
12011189 }
12021190
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 ) {
12041203if ($ throwException ) {
12051204throw new RuntimeException (sprintf ('Error while sending signal `%s`. ' ,$ signal ));
12061205 }