function Process::getIterator
Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
Parameters
int $flags A bit field of Process::ITER_* flags:
Return value
\Generator<string, string>
Throws
LogicException in case the output has been disabled
LogicException In case the process is not started
File
-
vendor/
symfony/ process/ Process.php, line 640
Class
- Process
- Process is a thin wrapper around proc_* functions to easily start independent PHP processes.
Namespace
Symfony\Component\ProcessCode
public function getIterator(int $flags = 0) : \Generator {
$this->readPipesForOutput(__FUNCTION__, false);
$clearOutput = !(self::ITER_KEEP_OUTPUT & $flags);
$blocking = !(self::ITER_NON_BLOCKING & $flags);
$yieldOut = !(self::ITER_SKIP_OUT & $flags);
$yieldErr = !(self::ITER_SKIP_ERR & $flags);
while (null !== $this->callback || $yieldOut && !feof($this->stdout) || $yieldErr && !feof($this->stderr)) {
if ($yieldOut) {
$out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
if (isset($out[0])) {
if ($clearOutput) {
$this->clearOutput();
}
else {
$this->incrementalOutputOffset = ftell($this->stdout);
}
(yield self::OUT => $out);
}
}
if ($yieldErr) {
$err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
if (isset($err[0])) {
if ($clearOutput) {
$this->clearErrorOutput();
}
else {
$this->incrementalErrorOutputOffset = ftell($this->stderr);
}
(yield self::ERR => $err);
}
}
if (!$blocking && !isset($out[0]) && !isset($err[0])) {
(yield self::OUT => '');
}
$this->checkTimeout();
$this->readPipesForOutput(__FUNCTION__, $blocking);
}
}