{"record":{"id":"626b57a59e6a1fed","repo":"symfony/process","slug":"process-is-already-running","errorCode":null,"errorMessage":"Process is already running.","messagePattern":"Process is already running\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Process.php","lineNumber":321,"sourceCode":"     * returns while the process runs in the background.\n     *\n     * The termination of the process can be awaited with wait().\n     *\n     * The callback receives the type of output (out or err) and some bytes from\n     * the output in real-time while writing the standard input to the process.\n     * It allows to have feedback from the independent process during execution.\n     *\n     * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some\n     *                                                            output available on STDOUT or STDERR\n     * @param EnvArray                                  $env\n     *\n     * @throws ProcessStartFailedException When process can't be launched\n     * @throws RuntimeException            When process is already running\n     */\n    public function start(?callable $callback = null, array $env = []): void\n    {\n        if ($this->isRunning()) {\n            throw new RuntimeException('Process is already running.');\n        }\n\n        $this->resetProcessData();\n        $this->starttime = $this->lastOutputTime = microtime(true);\n        $this->callback = $this->buildCallback($callback);\n        $descriptors = $this->getDescriptors(null !== $callback);\n\n        if ($this->env) {\n            $env += '\\\\' === \\DIRECTORY_SEPARATOR ? array_diff_ukey($this->env, $env, 'strcasecmp') : $this->env;\n        }\n\n        $env += '\\\\' === \\DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv(), $env, 'strcasecmp') : $this->getDefaultEnv();\n\n        if (\\is_array($commandline = $this->commandline)) {\n            $commandline = array_values(array_map(strval(...), $commandline));\n        } else {\n            $commandline = $this->replacePlaceholders($commandline, $env);\n        }","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Process.php#L303-L339","documentation":"A Process object represents at most one running process; calling start() while the previous instance is still running would leak the running process and corrupt the object's state, so start() throws RuntimeException if isRunning() is true.","triggerScenarios":"Calling $process->start() (directly or via run()) twice without waiting for the first run to finish — e.g. calling start() again after start() without stop()/wait(), or calling run() concurrently on the same instance.","commonSituations":"Loops that re-start the same Process object per item; retry logic that re-calls start on a still-running process; long-running commands combined with a second start call in request handling.","solutions":["Call $process->wait() (or stop()) before starting again, or check $process->isRunning().","Create a new Process instance for each execution instead of reusing one object.","Restructure concurrent launches into separate Process instances started in parallel.","Guard start with if (!$process->isRunning()) { $process->start(); }."],"exampleFix":"// before\n$process->start();\n$process->start(); // RuntimeException\n\n// after\n$process->start();\n$process->wait();\n$process->start(); // ok, previous run finished","handlingStrategy":"validation","validationCode":"if ($process->isRunning()) {\n    $process->wait(); // or stop()\n}\n$process->start();","typeGuard":null,"tryCatchPattern":"try {\n    $process->start();\n} catch (\\RuntimeException $e) {\n    if ($e->getMessage() === 'Process is already running.') {\n        $process->wait();\n        $process->start();\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Create a fresh Process instance per execution instead of reusing one object.","Always pair start() with wait()/stop() before any subsequent start().","Never call start()/run() concurrently on the same instance; parallelize with separate instances.","Wrap lifecycle transitions in a small helper that enforces wait-before-start."],"tags":["php","symfony-process","process-lifecycle","invalid-state"],"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"}