diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index f8a3293b1293..7d2535095ea4 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -591,7 +591,7 @@ public function isRunning() */ public function stop($timeout=10) { - $timeoutMicro = (int) $timeout*10E6; + $timeoutMicro = (int) $timeout*1E6; if ($this->isRunning()) { proc_terminate($this->process); $time = 0; @@ -600,6 +600,10 @@ public function stop($timeout=10) usleep(1000); } + if (!defined('PHP_WINDOWS_VERSION_BUILD') && $this->isRunning()) { + proc_terminate($this->process, SIGKILL); + } + foreach ($this->pipes as $pipe) { fclose($pipe); } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 51d51f40b87b..7f622d38ac63 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -44,6 +44,31 @@ public function testNullTimeout() $this->assertNull($p->getTimeout()); } + public function testStopWithTimeoutIsActuallyWorking() + { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $this->markTestSkipped('Stop with timeout does not work on windows, it requires posix signals'); + } + if (!function_exists('pcntl_signal')) { + $this->markTestSkipped('This test require pcntl_signal function'); + } + + // exec is mandatory here since we send a signal to the process + // see https://github.com/symfony/symfony/issues/5030 about prepending + // command with exec + $p = $this->getProcess('exec php '.__DIR__.'/NonStopableProcess.php 3'); + $p->start(); + usleep(100000); + $start = microtime(true); + $p->stop(1.1); + while ($p->isRunning()) { + usleep(1000); + } + $duration = microtime(true) - $start; + + $this->assertLessThan(1.3, $duration); + } + /** * tests results from sub processes * diff --git a/src/Symfony/Component/Process/Tests/NonStopableProcess.php b/src/Symfony/Component/Process/Tests/NonStopableProcess.php new file mode 100644 index 000000000000..a4db838256af --- /dev/null +++ b/src/Symfony/Component/Process/Tests/NonStopableProcess.php @@ -0,0 +1,37 @@ + (microtime(true) - $start)) { + usleep(1000); +}