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\PipesCode
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);
}