{"record":{"id":"c020ea06d1bc3b98","repo":"symfony/process","slug":"a-temporary-file-could-not-be-opened-to-write-the-process","errorCode":null,"errorMessage":"A temporary file could not be opened to write the process output: ","messagePattern":"A temporary file could not be opened to write the process output: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Pipes/WindowsPipes.php","lineNumber":62,"sourceCode":"            //\n            // @see https://bugs.php.net/51800\n            $pipes = [\n                Process::STDOUT => Process::OUT,\n                Process::STDERR => Process::ERR,\n            ];\n            $tmpDir = sys_get_temp_dir();\n            $lastError = 'unknown reason';\n            set_error_handler(static function ($type, $msg) use (&$lastError) { $lastError = $msg; });\n            for ($i = 0;; ++$i) {\n                foreach ($pipes as $pipe => $name) {\n                    $file = \\sprintf('%s\\\\sf_proc_%02X.%s', $tmpDir, $i, $name);\n\n                    if (!$h = fopen($file.'.lock', 'w')) {\n                        if (file_exists($file.'.lock')) {\n                            continue 2;\n                        }\n                        restore_error_handler();\n                        throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError);\n                    }\n                    if (!flock($h, \\LOCK_EX | \\LOCK_NB)) {\n                        continue 2;\n                    }\n                    if (isset($this->lockHandles[$pipe])) {\n                        flock($this->lockHandles[$pipe], \\LOCK_UN);\n                        fclose($this->lockHandles[$pipe]);\n                    }\n                    $this->lockHandles[$pipe] = $h;\n\n                    if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) {\n                        flock($this->lockHandles[$pipe], \\LOCK_UN);\n                        fclose($this->lockHandles[$pipe]);\n                        unset($this->lockHandles[$pipe]);\n                        continue 2;\n                    }\n                    $this->fileHandles[$pipe] = $h;\n                    $this->files[$pipe] = $file;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Pipes/WindowsPipes.php#L44-L80","documentation":"On Windows, WindowsPipes manages process output through temporary files guarded by .lock files opened with fopen and locked with flock. If fopen on the lock file fails (and the lock file does not already exist, which would mean contention), the constructor throws RuntimeException including the last PHP error message, because output cannot be captured at all.","triggerScenarios":"fopen($file.'.lock', 'w') returns false while creating per-pipe temp files in the constructor — disk full, temp directory not writable, or the filesystem denying file creation; $lastError holds the underlying PHP warning text.","commonSituations":"Windows machines with restricted %TEMP% directories; antivirus or permissions software blocking file creation in the temp path; full disks on CI Windows runners.","solutions":["Check the $lastError suffix in the message to identify the underlying fopen failure (permissions, disk full, etc.).","Verify the temp directory (sys_get_temp_dir() / %TEMP%) is writable by the PHP process user.","Free disk space or change TMP/TEMP environment variables to a writable location.","Exclude the temp directory from antivirus/EDR interference and retry."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"if ('\\\\' === \\DIRECTORY_SEPARATOR) {\n    $tmp = sys_get_temp_dir();\n    if (!is_dir($tmp) || !is_writable($tmp)) {\n        throw new \\RuntimeException(sprintf('Windows temp dir %s not writable; WindowsPipes will fail', $tmp));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $process = new Process($cmd);\n    $process->start();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'A temporary file could not be opened')) {\n        // inspect TMP/TEMP permissions and disk space; $lastError is appended to the message\n    }\n    throw $e;\n}","preventionTips":["On Windows hosts, ensure %TEMP% is writable by the PHP service account.","Exclude the temp directory from antivirus/EDR that blocks transient file creation.","Monitor disk space on Windows CI runners.","Set TMP/TEMP env vars to a known-writable directory in constrained environments."],"tags":["php","symfony-process","windows","temp-file","filesystem"],"backgroundTag":"file-open-failed","analyzedSha":"99b85026db14a68f02c6f3eeb01a1170ca25c491","analyzedAt":"2026-09-14T11:23:33.683Z","contentChangedAt":"2026-09-14T11:23:33.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}