diff --git a/src/Symfony/Component/Process/ProcessPipes.php b/src/Symfony/Component/Process/ProcessPipes.php index 67b11e615ba7..d1b434ebf884 100644 --- a/src/Symfony/Component/Process/ProcessPipes.php +++ b/src/Symfony/Component/Process/ProcessPipes.php @@ -29,6 +29,8 @@ class ProcessPipes /** @var Boolean */ private $ttyMode; + const CHUNK_SIZE = 16384; + public function __construct($useFiles, $ttyMode) { $this->useFiles = (Boolean) $useFiles; @@ -233,7 +235,7 @@ private function readFileHandles($close = false) $data = ''; $dataread = null; while (!feof($fileHandle)) { - if (false !== $dataread = fread($fileHandle, 16392)) { + if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) { $data .= $dataread; } } @@ -291,7 +293,7 @@ private function readStreams($blocking, $close = false) $type = array_search($pipe, $this->pipes); $data = ''; - while ($dataread = fread($pipe, 8192)) { + while ($dataread = fread($pipe, self::CHUNK_SIZE)) { $data .= $dataread; } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 6401ec33e482..bc6fcf473b09 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\RuntimeException; +use Symfony\Component\Process\ProcessPipes; /** * @author Robert Schönthal @@ -87,18 +88,20 @@ public function testAllOutputIsActuallyReadOnTermination() // has terminated so the internal pipes array is already empty. normally // the call to start() will not read any data as the process will not have // generated output, but this is non-deterministic so we must count it as - // a possibility. therefore we need 2 * 8192 plus another byte which will - // never be read. - $expectedOutputSize = 16385; + // a possibility. therefore we need 2 * ProcessPipes::CHUNK_SIZE plus + // another byte which will never be read. + $expectedOutputSize = ProcessPipes::CHUNK_SIZE * 2 + 2; $code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize); $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); $p->start(); - usleep(250000); + // Let's wait enough time for process to finish... + // Here we don't call Process::run or Process::wait to avoid any read of pipes + usleep(500000); if ($p->isRunning()) { - $this->fail('Process execution did not complete in the required time frame'); + $this->markTestSkipped('Process execution did not complete in the required time frame'); } $o = $p->getOutput();