[Process] Use stream based storage to avoid memory issues
This commit is contained in:
parent
b7024483e3
commit
da73125a9c
|
@ -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;
|
||||
|
|
Reference in New Issue