{"record":{"id":"b3355c69f282fab5","repo":"symfony/process","slug":"unable-to-write-temporary-ini-file","errorCode":null,"errorMessage":"Unable to write temporary ini file.","messagePattern":"Unable to write temporary ini file\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"PhpSubprocess.php","lineNumber":135,"sourceCode":"\n            $content .= $data.\"\\n\";\n        }\n\n        // Merge loaded settings into our ini content, if it is valid\n        $config = parse_ini_string($content);\n        $loaded = ini_get_all(null, false);\n\n        if (false === $config || false === $loaded) {\n            throw new RuntimeException('Unable to parse ini data.');\n        }\n\n        $content .= $this->mergeLoadedConfig($loaded, $config);\n\n        // Work-around for https://bugs.php.net/bug.php?id=75932\n        $content .= \"opcache.enable_cli=0\\n\";\n\n        if (false === @file_put_contents($tmpfile, $content)) {\n            throw new RuntimeException('Unable to write temporary ini file.');\n        }\n\n        return $tmpfile;\n    }\n\n    private function mergeLoadedConfig(array $loadedConfig, array $iniConfig): string\n    {\n        $content = '';\n\n        foreach ($loadedConfig as $name => $value) {\n            if (!\\is_string($value)) {\n                continue;\n            }\n\n            if (!isset($iniConfig[$name]) || $iniConfig[$name] !== $value) {\n                // Double-quote escape each value\n                $content .= $name.'=\"'.addcslashes($value, '\\\\\"').\"\\\"\\n\";\n            }","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/PhpSubprocess.php#L117-L153","documentation":"After assembling the temporary INI content, PhpSubprocess writes it with file_put_contents to a temp file; if the write fails (returns false) the child PHP process cannot be launched with the merged config, so a RuntimeException is thrown immediately.","triggerScenarios":"writeTmpIni throws when @file_put_contents($tmpfile, $content) returns false — typically because the temp directory is not writable, the disk is full, an open_basedir restriction excludes the temp path, or the file could not be created.","commonSituations":"Containers or CI runners with read-only /tmp; open_basedir settings that exclude sys_get_temp_dir(); disk-quota exhaustion; SELinux/AppArmor blocking writes to the temp directory.","solutions":["Verify sys_get_temp_dir() exists and is writable: php -r 'var_dump(is_writable(sys_get_temp_dir()));'.","Fix permissions on the temp directory or point sys_temp_dir/tmp to a writable path in php.ini.","Remove open_basedir restrictions or include the temp dir in open_basedir.","Free disk space / raise quota if the filesystem is full."],"exampleFix":"// before\n$process = new PhpSubprocess($phpBinary);\n\n// after (fail fast with a clear cause)\n$tmp = sys_get_temp_dir();\nif (!is_dir($tmp) || !is_writable($tmp)) {\n    throw new \\RuntimeException(sprintf('Temp dir %s is not writable; PhpSubprocess cannot create its ini file', $tmp));\n}\n$process = new PhpSubprocess($phpBinary);","handlingStrategy":"validation","validationCode":"$tmp = sys_get_temp_dir();\nif (!is_dir($tmp) || !is_writable($tmp) || (function_exists('disk_free_space') && disk_free_space($tmp) < 1024 * 1024)) {\n    throw new \\RuntimeException(sprintf('Temp dir %s unusable for PhpSubprocess ini file', $tmp));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $proc = new PhpSubprocess($phpBinary);\n} catch (\\RuntimeException $e) {\n    if (str_starts_with($e->getMessage(), 'Unable to write temporary ini file')) {\n        // check disk space / open_basedir / permissions before retrying\n    }\n    throw $e;\n}","preventionTips":["Keep sys_get_temp_dir() writable and inside open_basedir where open_basedir is set.","Monitor disk space on CI runners and containers running process-heavy workloads.","Set sys_temp_dir explicitly to a writable volume in containerized deployments.","Exclude temp dirs from antivirus/EDR file-creation blocks."],"tags":["php","filesystem","temp-file","permissions"],"backgroundTag":"file-write-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"}