private function write($blocking, $close)
{
if (empty($this->pipes)) {
return;
}
$this->unblock();
$r = null !== $this->input ? ['input' => $this->input] : null;
$w = isset($this->pipes[0]) ? [$this->pipes[0]] : null;
$e = null;
if (false === ($n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1000000.0 : 0))) {
if (!$this->hasSystemCallBeenInterrupted()) {
$this->pipes = [];
}
return;
}
if (0 === $n) {
return;
}
if (null !== $w && 0 < count($r)) {
$data = '';
while ($dataread = fread($r['input'], self::CHUNK_SIZE)) {
$data .= $dataread;
}
$this->inputBuffer .= $data;
if (false === $data || true === $close && feof($r['input']) && '' === $data) {
$this->input = null;
}
}
if (null !== $w && 0 < count($w)) {
while (strlen($this->inputBuffer)) {
$written = fwrite($w[0], $this->inputBuffer, 2 << 18);
if ($written > 0) {
$this->inputBuffer = (string) substr($this->inputBuffer, $written);
} else {
break;
}
}
}
if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
fclose($this->pipes[0]);
unset($this->pipes[0]);
}
}