You are here

public function WindowsPipes::readAndWrite in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/process/Pipes/WindowsPipes.php \Symfony\Component\Process\Pipes\WindowsPipes::readAndWrite()

Reads data in file handles and pipes.

Parameters

bool $blocking Whether to use blocking calls or not.:

bool $close Whether to close pipes if they've reached EOF.:

Return value

string[] An array of read data indexed by their fd.

Overrides PipesInterface::readAndWrite

File

vendor/symfony/process/Pipes/WindowsPipes.php, line 110

Class

WindowsPipes
WindowsPipes implementation uses temporary files as handles.

Namespace

Symfony\Component\Process\Pipes

Code

public function readAndWrite($blocking, $close = false) {
  $this
    ->write($blocking, $close);
  $read = array();
  $fh = $this->fileHandles;
  foreach ($fh as $type => $fileHandle) {
    if (0 !== fseek($fileHandle, $this->readBytes[$type])) {
      continue;
    }
    $data = '';
    $dataread = null;
    while (!feof($fileHandle)) {
      if (false !== ($dataread = fread($fileHandle, self::CHUNK_SIZE))) {
        $data .= $dataread;
      }
    }
    if (0 < ($length = strlen($data))) {
      $this->readBytes[$type] += $length;
      $read[$type] = $data;
    }
    if (false === $dataread || true === $close && feof($fileHandle) && '' === $data) {
      fclose($this->fileHandles[$type]);
      unset($this->fileHandles[$type]);
    }
  }
  return $read;
}