diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index e0f49a7e3b..157499d10f 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -378,7 +378,11 @@ class Process $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true); - return $this->stdout; + if (false === $ret = stream_get_contents($this->stdout, -1, 0)) { + return ''; + } + + return $ret; } /** @@ -395,16 +399,13 @@ class Process { $this->requireProcessIsStarted(__FUNCTION__); - $data = $this->getOutput(); - - $latest = substr($data, $this->incrementalOutputOffset); + $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset); + $this->incrementalOutputOffset = ftell($this->stdout); if (false === $latest) { return ''; } - $this->incrementalOutputOffset = strlen($data); - return $latest; } @@ -421,7 +422,11 @@ class Process $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true); - return $this->stderr; + if (false === $ret = stream_get_contents($this->stderr, -1, 0)) { + return ''; + } + + return $ret; } /** @@ -439,16 +444,13 @@ class Process { $this->requireProcessIsStarted(__FUNCTION__); - $data = $this->getErrorOutput(); - - $latest = substr($data, $this->incrementalErrorOutputOffset); + $latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset); + $this->incrementalErrorOutputOffset = ftell($this->stderr); if (false === $latest) { return ''; } - $this->incrementalErrorOutputOffset = strlen($data); - return $latest; } @@ -666,21 +668,29 @@ class Process /** * Adds a line to the STDOUT stream. * + * @internal + * * @param string $line The line to append */ public function addOutput($line) { - $this->stdout .= $line; + fseek($this->stdout, 0, SEEK_END); + fwrite($this->stdout, $line); + fseek($this->stdout, $this->incrementalOutputOffset); } /** * Adds a line to the STDERR stream. * + * @internal + * * @param string $line The line to append */ public function addErrorOutput($line) { - $this->stderr .= $line; + fseek($this->stderr, 0, SEEK_END); + fwrite($this->stderr, $line); + fseek($this->stderr, $this->incrementalErrorOutputOffset); } /** @@ -1126,8 +1136,8 @@ class Process $this->exitcode = null; $this->fallbackStatus = array(); $this->processInformation = null; - $this->stdout = null; - $this->stderr = null; + $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+'); + $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+'); $this->process = null; $this->latestSignal = null; $this->status = self::STATUS_READY;