Symfony\Component\Process\Process::getIncrementalOutput PHP Method

getIncrementalOutput() public method

In comparison with the getOutput method which always return the whole output, this one returns the new output since the last call.
public getIncrementalOutput ( ) : string
return string The process output since the last call
    public function getIncrementalOutput()
    {
        $this->readPipesForOutput(__FUNCTION__);
        $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
        $this->incrementalOutputOffset = ftell($this->stdout);
        if (false === $latest) {
            return '';
        }
        return $latest;
    }

Usage Example

 /**
  * Looks into and processes the child's output
  *
  * @param string $childName
  * @return void
  */
 public function processOutput($childName)
 {
     $output = $this->outputBuffer . $this->process->getIncrementalOutput();
     $errorOutput = $this->errorOutputBuffer . $this->process->getIncrementalErrorOutput();
     $outputLines = explode("\n", $output);
     $errorOutputLines = explode("\n", $errorOutput);
     if (count($outputLines) > 0) {
         $lastItem = array_pop($outputLines);
         $this->outputBuffer = $lastItem;
         $this->bufferLength += implode("\n", $outputLines);
         foreach ($outputLines as $line) {
             if (strstr($line, "[[CHILD::BUSY]]")) {
                 $this->parent->verboseOutput('<info>' . $childName . ' BUSY</info>');
                 $this->status = ChildProcessContainer::STATUS_BUSY;
             } elseif (strstr($line, "[[CHILD::READY]]")) {
                 $this->parent->verboseOutput('<info>' . $childName . ' READY</info>');
                 if ($this->status != ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY) {
                     $this->status = ChildProcessContainer::STATUS_READY;
                 } else {
                     $this->status = ChildProcessContainer::STATUS_SLEEPY;
                 }
             } elseif (strlen($line) > 0) {
                 $this->parent->verboseOutput('<info>OUTPUT ' . $childName . ':</info>' . $line);
             }
         }
     }
     if (count($errorOutputLines) > 0) {
         $lastItemError = array_pop($errorOutputLines);
         $this->errorOutputBuffer = $lastItemError;
         $knownErrorOutput = implode("\n", $errorOutputLines);
         $this->bufferLength += strlen($knownErrorOutput);
     }
 }
All Usage Examples Of Symfony\Component\Process\Process::getIncrementalOutput