{"record":{"id":"558dc7c59e77dbc0","repo":"symfony/process","slug":"setting-options-while-the-process-is-running-is-not-possible","errorCode":null,"errorMessage":"Setting options while the process is running is not possible.","messagePattern":"Setting options while the process is running is not possible\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Process.php","lineNumber":1255,"sourceCode":"        if (!$this->isStarted()) {\n            throw new LogicException('Start time is only available after process start.');\n        }\n\n        return $this->starttime;\n    }\n\n    /**\n     * Defines options to pass to the underlying proc_open().\n     *\n     * @see https://php.net/proc_open for the options supported by PHP.\n     *\n     * Enabling the \"create_new_console\" option allows a subprocess to continue\n     * to run after the main process exited, on both Windows and *nix\n     */\n    public function setOptions(array $options): void\n    {\n        if ($this->isRunning()) {\n            throw new RuntimeException('Setting options while the process is running is not possible.');\n        }\n\n        $defaultOptions = $this->options;\n        $existingOptions = ['blocking_pipes', 'create_process_group', 'create_new_console'];\n\n        foreach ($options as $key => $value) {\n            if (!\\in_array($key, $existingOptions)) {\n                $this->options = $defaultOptions;\n                throw new LogicException(\\sprintf('Invalid option \"%s\" passed to \"%s()\". Supported options are \"%s\".', $key, __METHOD__, implode('\", \"', $existingOptions)));\n            }\n            $this->options[$key] = $value;\n        }\n    }\n\n    /**\n     * Defines a list of posix signals that will not be propagated to the process.\n     *\n     * @param list<\\SIG*> $signals","sourceCodeStart":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Process.php#L1237-L1273","documentation":"setOptions() throws this RuntimeException when called while the process is running. Options such as blocking_pipes, create_process_group, and create_new_console are applied by the OS when the process is spawned, so they are immutable once started.","triggerScenarios":"Calling setOptions([...]) after start()/run() on a still-running process; seen in tests like testOptionCreateNewConsole and testItReturnsFastAfterStart when mutating options late.","commonSituations":"Enabling create_new_console so a subprocess survives the parent exit — but applying it after start; centralized config code adjusting process options in response to runtime events.","solutions":["Call setOptions() before start()/run().","Guard with if (!$process->isRunning()) or stop the process before changing options.","Recreate the Process with the desired options and start it again."],"exampleFix":"// before\n$process->start();\n$process->setOptions(['create_new_console' => true]); // RuntimeException\n\n// after\n$process->setOptions(['create_new_console' => true]);\n$process->start();","handlingStrategy":"validation","validationCode":"if (!$process->isRunning()) {\n    $process->setOptions(['create_new_console' => true]);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $process->setOptions($options);\n} catch (\\RuntimeException $e) {\n    // running: recreate the process with the new options\n}","preventionTips":["Set all options (blocking_pipes, create_process_group, create_new_console) before start().","Keep an immutable pre-start configuration phase; don't mutate Process objects after start().","Only use keys from the documented list (blocking_pipes, create_process_group, create_new_console)."],"tags":["process","symfony","runtime-exception","options","invalid-state-transition"],"backgroundTag":"invalid-state-transition","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"}