laravel/framework · critical · RuntimeException

Due to PHP limitations, the fork driver may not be used…

Error message

Due to PHP limitations, the fork driver may not be used within web requests.

What it means

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.

Solutions

  1. Move the Concurrency::run(...) call into an Artisan command, queued job, or CLI script.
  2. Switch the default driver to 'process' or 'sync' for request-path work.
  3. Dispatch the work to a queue and let a worker (console) process it.

Example fix

// before (inside a controller)
$result = Concurrency::driver('fork')->run([...]);
// after
// dispatch a job instead
ProcessThings::dispatch($payload);
// the job's handle() runs in the queue worker (console context)
Defensive patterns

Strategy: validation

Validate before calling

if (app()->runningInConsole()) {
    $result = Concurrency::driver('fork')->run($tasks);
} else {
    // dispatch to a queue/worker instead
    \App\Jobs\RunConcurrentTasks::dispatch($tasks);
}

Type guard

function canUseForkDriver(): bool {
    return app()->runningInConsole() && PHP_OS_FAMILY !== 'Windows';
}

Try / catch

try {
    $result = Concurrency::driver('fork')->run($tasks);
} catch (\RuntimeException $e) {
    $result = Concurrency::driver('process')->run($tasks);
}

Prevention

When it happens

Trigger: Configuring the 'fork' concurrency driver and invoking Concurrency::run(...) from within a controller, middleware, or any HTTP-requested code path (runningInConsole() returns false).

Common situations: 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.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/7a2d2190d4df5529. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Concurrency/ConcurrencyManager.php:48

     *
     * @return \Illuminate\Concurrency\ProcessDriver
     */
    public function createProcessDriver()
    {
        return new ProcessDriver($this->app->make(ProcessFactory::class));
    }

    /**
     * Create an instance of the fork concurrency driver.
     *
     * @return \Illuminate\Concurrency\ForkDriver
     *
     * @throws \RuntimeException
     */
    public function createForkDriver()
    {
        if (! $this->app->runningInConsole()) {
            throw new RuntimeException('Due to PHP limitations, the fork driver may not be used within web requests.');
        }

        if (! class_exists(Fork::class)) {
            throw new RuntimeException('Please install the "spatie/fork" Composer package in order to utilize the "fork" driver.');
        }

        return new ForkDriver;
    }

    /**
     * Create an instance of the sync concurrency driver.
     *
     * @return \Illuminate\Concurrency\SyncDriver
     */
    public function createSyncDriver()
    {
        return new SyncDriver;
    }

View on GitHub (pinned to e0f6eb3518)