{"record":{"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":"critical","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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Concurrency/ConcurrencyManager.php#L30-L66","documentation":"Thrown by ConcurrencyManager::createForkDriver() when the application is not running in console (i.e. within a web request). PHP cannot safely fork a process that is already serving an HTTP request (shared sockets, signal handling, memory state), so the fork driver is hard-blocked in web context with a RuntimeException.","triggerScenarios":"Configuring the 'fork' concurrency driver and invoking Concurrency::run(...) from within a controller, middleware, or any HTTP-requested code path (runningInConsole() returns false).","commonSituations":"Running concurrent work via the fork driver inside a queued job dispatched from a web request that is actually executed synchronously; testing fork concurrency through a local dev web server; misclassifying a worker context.","solutions":["Move the Concurrency::run(...) call into an Artisan command, queued job, or CLI script.","Switch the default driver to 'process' or 'sync' for request-path work.","Dispatch the work to a queue and let a worker (console) process it."],"exampleFix":"// before (inside a controller)\n$result = Concurrency::driver('fork')->run([...]);\n// after\n// dispatch a job instead\nProcessThings::dispatch($payload);\n// the job's handle() runs in the queue worker (console context)","handlingStrategy":"validation","validationCode":"if (app()->runningInConsole()) {\n    $result = Concurrency::driver('fork')->run($tasks);\n} else {\n    // dispatch to a queue/worker instead\n    \\App\\Jobs\\RunConcurrentTasks::dispatch($tasks);\n}","typeGuard":"function canUseForkDriver(): bool {\n    return app()->runningInConsole() && PHP_OS_FAMILY !== 'Windows';\n}","tryCatchPattern":"try {\n    $result = Concurrency::driver('fork')->run($tasks);\n} catch (\\RuntimeException $e) {\n    $result = Concurrency::driver('process')->run($tasks);\n}","preventionTips":["Restrict the fork driver to CLI/queue-worker entry points.","Default the concurrency driver to 'process' for general use.","Dispatch concurrent work to jobs when called from the web layer."],"tags":["concurrency","fork","runtime-context","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}