Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UnixPipes.php

function UnixPipes::readAndWrite

Overrides PipesInterface::readAndWrite

File

vendor/symfony/process/Pipes/UnixPipes.php, line 89

Class

UnixPipes
UnixPipes implementation uses unix pipes as handles.

Namespace

Symfony\Component\Process\Pipes

Code

public function readAndWrite(bool $blocking, bool $close = false) : array {
    $this->unblock();
    $w = $this->write();
    $read = $e = [];
    $r = $this->pipes;
    unset($r[0]);
    // let's have a look if something changed in streams
    set_error_handler($this->handleError(...));
    if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1000000.0 : 0)) {
        restore_error_handler();
        // if a system call has been interrupted, forget about it, let's try again
        // otherwise, an error occurred, let's reset pipes
        if (!$this->hasSystemCallBeenInterrupted()) {
            $this->pipes = [];
        }
        return $read;
    }
    restore_error_handler();
    foreach ($r as $pipe) {
        // prior PHP 5.4 the array passed to stream_select is modified and
        // lose key association, we have to find back the key
        $read[$type = array_search($pipe, $this->pipes, true)] = '';
        do {
            $data = @fread($pipe, self::CHUNK_SIZE);
            $read[$type] .= $data;
        } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
        if (!isset($read[$type][0])) {
            unset($read[$type]);
        }
        if ($close && feof($pipe)) {
            fclose($pipe);
            unset($this->pipes[$type]);
        }
    }
    return $read;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal