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

Breadcrumb

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

function WindowsPipes::__construct

Overrides AbstractPipes::__construct

File

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

Class

WindowsPipes
WindowsPipes implementation uses temporary files as handles.

Namespace

Symfony\Component\Process\Pipes

Code

public function __construct(mixed $input, bool $haveReadSupport) {
    if ($this->haveReadSupport) {
        // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
        // Workaround for this problem is to use temporary files instead of pipes on Windows platform.
        //
        // @see https://bugs.php.net/51800
        $pipes = [
            Process::STDOUT => Process::OUT,
            Process::STDERR => Process::ERR,
        ];
        $tmpDir = sys_get_temp_dir();
        $lastError = 'unknown reason';
        set_error_handler(function ($type, $msg) use (&$lastError) {
            $lastError = $msg;
        });
        for ($i = 0;; ++$i) {
            foreach ($pipes as $pipe => $name) {
                $file = \sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
                if (!($h = fopen($file . '.lock', 'w'))) {
                    if (file_exists($file . '.lock')) {
                        continue 2;
                    }
                    restore_error_handler();
                    throw new RuntimeException('A temporary file could not be opened to write the process output: ' . $lastError);
                }
                if (!flock($h, \LOCK_EX | \LOCK_NB)) {
                    continue 2;
                }
                if (isset($this->lockHandles[$pipe])) {
                    flock($this->lockHandles[$pipe], \LOCK_UN);
                    fclose($this->lockHandles[$pipe]);
                }
                $this->lockHandles[$pipe] = $h;
                if (!($h = fopen($file, 'w')) || !fclose($h) || !($h = fopen($file, 'r'))) {
                    flock($this->lockHandles[$pipe], \LOCK_UN);
                    fclose($this->lockHandles[$pipe]);
                    unset($this->lockHandles[$pipe]);
                    continue 2;
                }
                $this->fileHandles[$pipe] = $h;
                $this->files[$pipe] = $file;
            }
            break;
        }
        restore_error_handler();
    }
    parent::__construct($input);
}

API Navigation

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