{"record":{"id":"2defa12c7f19825b","repo":"sebastianbergmann/phpunit","slug":"unable-to-create-temporary-file-for-redirected-out","errorCode":null,"errorMessage":"Unable to create temporary file for redirected output","messagePattern":"Unable to create temporary file for redirected output","errorType":"exception","errorClass":"PHPUnit\\Util\\PHP\\PhpProcessException","httpStatus":null,"severity":"error","filePath":"src/Util/PHP/JobRunner.php","lineNumber":196,"sourceCode":"\n                if (is_array($value)) {\n                    continue;\n                }\n\n                $environmentVariables[$key] = $value;\n            }\n\n            $environmentVariables = array_merge($environmentVariables, $job->environmentVariables());\n        }\n\n        $mergedOutputStream = null;\n\n        if ($job->redirectErrors()) {\n            $mergedOutputStream = tmpfile();\n\n            if ($mergedOutputStream === false) {\n                // @codeCoverageIgnoreStart\n                throw new PhpProcessException('Unable to create temporary file for redirected output');\n                // @codeCoverageIgnoreEnd\n            }\n\n            $pipeSpec = [\n                0 => ['pipe', 'r'],\n                1 => $mergedOutputStream,\n                2 => $mergedOutputStream,\n            ];\n        } else {\n            $pipeSpec = [\n                0 => ['pipe', 'r'],\n                1 => ['pipe', 'w'],\n                2 => ['pipe', 'w'],\n            ];\n        }\n\n        $process = proc_open(\n            $this->buildCommand($job, $temporaryFile),","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Util/PHP/JobRunner.php#L178-L214","documentation":"When a job is configured to redirect errors (merged stdout/stderr into one stream), JobRunner::startProcess() allocates that stream with tmpfile(). If tmpfile() fails it throws PhpProcessException('Unable to create temporary file for redirected output'). Like the other JobRunner failures this indicates the system temp directory cannot be used.","triggerScenarios":"Running process-isolated tests that redirect errors while the temp directory is unwritable, full, or excluded by open_basedir, so tmpfile() cannot create its anonymous temporary file.","commonSituations":"Docker images with read-only root filesystems and no /tmp tmpfs; CI runners with full disks; minimal VMs where /tmp is missing entirely or mode 000.","solutions":["Ensure /tmp (or TMPDIR) exists and is writable by the test user: `mkdir -p /tmp && chmod 1777 /tmp`","Mount a writable tmpfs at /tmp in the container definition","Free disk space on the volume hosting the temp directory","Check open_basedir includes the temp directory if it is configured"],"exampleFix":"# before\n$ docker run --read-only my-ci vendor/bin/phpunit\n# PhpProcessException: Unable to create temporary file for redirected output\n\n# after\n$ docker run --read-only --tmpfs /tmp:rw,size=64m my-ci vendor/bin/phpunit","handlingStrategy":"try-catch","validationCode":"if (!is_writable(sys_get_temp_dir()) || disk_free_space(sys_get_temp_dir()) === false) {\n    throw new RuntimeException('Temp directory unusable for redirected output');\n}","typeGuard":null,"tryCatchPattern":"use PHPUnit\\Util\\PHP\\PhpProcessException;\n\ntry {\n    $runner->start($job); // job configured with redirectErrors()\n} catch (PhpProcessException $e) {\n    // disable error redirection for this run or fix the temp dir\n    error_log('Could not redirect child output: ' . $e->getMessage());\n}","preventionTips":["Mount a dedicated tmpfs at /tmp in read-only container images","Disk-space alerts on the volume backing the temp directory catch tmpfile() failures early","Test the exact container/CI image with one process-isolated test before scaling up"],"tags":["phpunit","process-isolation","temp-file","stderr-redirect","environment"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}