{"id":"7a2d2190d4df5529","repo":"laravel/framework","slug":"due-to-php-limitations-the-fork-driver-may-not-be","errorCode":null,"errorMessage":"Due to PHP limitations, the fork driver may not be used within web requests.","messagePattern":"Due to PHP limitations, the fork driver may not be used within web requests\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Concurrency/ConcurrencyManager.php","lineNumber":48,"sourceCode":"     *\n     * @return \\Illuminate\\Concurrency\\ProcessDriver\n     */\n    public function createProcessDriver()\n    {\n        return new ProcessDriver($this->app->make(ProcessFactory::class));\n    }\n\n    /**\n     * Create an instance of the fork concurrency driver.\n     *\n     * @return \\Illuminate\\Concurrency\\ForkDriver\n     *\n     * @throws \\RuntimeException\n     */\n    public function createForkDriver()\n    {\n        if (! $this->app->runningInConsole()) {\n            throw new RuntimeException('Due to PHP limitations, the fork driver may not be used within web requests.');\n        }\n\n        if (! class_exists(Fork::class)) {\n            throw new RuntimeException('Please install the \"spatie/fork\" Composer package in order to utilize the \"fork\" driver.');\n        }\n\n        return new ForkDriver;\n    }\n\n    /**\n     * Create an instance of the sync concurrency driver.\n     *\n     * @return \\Illuminate\\Concurrency\\SyncDriver\n     */\n    public function createSyncDriver()\n    {\n        return new SyncDriver;\n    }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Concurrency/ConcurrencyManager.php#L30-L66","documentation":"Thrown by ConcurrencyManager::createForkDriver() when the fork driver is requested outside of a CLI context. PHP's pcntl_fork is not available (and not safe) within a web request lifecycle, so the fork driver is gated behind runningInConsole(). RuntimeException is thrown.","triggerScenarios":"Configuring config('concurrency.default', 'fork') and then dispatching concurrency work during an HTTP request, queue job run via web worker, or any non-CLI entry point.","commonSituations":"Defaulting the concurrency driver to 'fork' globally while the same code path runs in both artisan commands and HTTP controllers. Forgetting that queued jobs may run under the web SAPI in some setups.","solutions":["Use the fork driver only in CLI/artisan contexts; switch the default to 'process' for web.","Conditionally choose the driver based on app()->runningInConsole().","Run the concurrent work as an artisan command or queued job dispatched from the request."],"exampleFix":"// before\nconfig(['concurrency.default' => 'fork']);\n\n// after\nconfig(['concurrency.default' => app()->runningInConsole() ? 'fork' : 'process']);","handlingStrategy":"fallback","validationCode":"$driver = app()->runningInConsole() ? 'fork' : 'process';\nconfig(['concurrency.default' => $driver]);","typeGuard":"function canUseFork(): bool { return app()->runningInConsole(); }","tryCatchPattern":"try {\n    $driver = app(\\Illuminate\\Concurrency\\ConcurrencyManager::class)->driver('fork');\n} catch (\\RuntimeException $e) {\n    $driver = app(\\Illuminate\\Concurrency\\ConcurrencyManager::class)->driver('process');\n}","preventionTips":["Default the global concurrency driver to 'process'; opt into 'fork' only inside artisan commands.","Branch on app()->runningInConsole() when selecting the driver.","Run fork-based work via queued jobs or commands, not request handlers."],"tags":["laravel","concurrency","fork","environment","cli-only"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}