From 89a5c1a845357eb9500a266678690a0ef385e60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Hems=C3=B8=20Rasmussen?= Date: Wed, 11 Apr 2012 23:08:57 +0200 Subject: [PATCH] [process] Added destructor to process to make sure handles are always closed in the right order. --- src/Symfony/Component/Process/Process.php | 6 ++++++ src/Symfony/Component/Process/Tests/ProcessTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index c7df0171a5..eed46a0c09 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -133,6 +133,12 @@ class Process $this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options); } + public function __destruct() + { + // stop() will check if we have a process running. + $this->stop(); + } + /** * Runs the process. * diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index d743af3a4d..b954f59ab0 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -121,6 +121,18 @@ class ProcessTest extends \PHPUnit_Framework_TestCase } } + public function testPhpDeadlock() + { + $this->markTestSkipped('Can course php to hang'); + + // Sleep dont work as it will allow the process to handle signals and close + // file handles from the other end. + $process = new Process('php -r "while (true) {}"'); + $process->start(); + + // PHP will deadlock when it tries to cleanup $process + } + public function responsesCodeProvider() { return array(