diff --git a/src/Illuminate/Concurrency/ProcessDriver.php b/src/Illuminate/Concurrency/ProcessDriver.php index 775245212cc0..8ba3345f9006 100644 --- a/src/Illuminate/Concurrency/ProcessDriver.php +++ b/src/Illuminate/Concurrency/ProcessDriver.php @@ -3,13 +3,13 @@ namespace Illuminate\Concurrency; use Closure; +use Illuminate\Console\Application; use Illuminate\Contracts\Concurrency\Driver; use Illuminate\Foundation\Defer\DeferredCallback; use Illuminate\Process\Factory as ProcessFactory; use Illuminate\Process\Pool; use Illuminate\Support\Arr; use Laravel\SerializableClosure\SerializableClosure; -use Symfony\Component\Process\PhpExecutableFinder; class ProcessDriver implements Driver { @@ -26,18 +26,13 @@ public function __construct(protected ProcessFactory $processFactory) */ public function run(Closure|array $tasks): array { - $php = $this->phpBinary(); - $artisan = $this->artisanBinary(); + $command = Application::formatCommandString('invoke-serialized-closure'); - $results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php, $artisan) { + $results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command) { foreach (Arr::wrap($tasks) as $task) { $pool->path(base_path())->env([ 'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)), - ])->command([ - $php, - $artisan, - 'invoke-serialized-closure', - ]); + ])->command($command); } })->start()->wait(); @@ -59,22 +54,14 @@ public function run(Closure|array $tasks): array */ public function defer(Closure|array $tasks): DeferredCallback { - return defer(fn () => $this->run($tasks)); - } - - /** - * Get the PHP binary. - */ - protected function phpBinary(): string - { - return (new PhpExecutableFinder)->find(false) ?: 'php'; - } + $command = Application::formatCommandString('invoke-serialized-closure'); - /** - * Get the Artisan binary. - */ - protected function artisanBinary(): string - { - return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan'; + return defer(function () use ($tasks, $command) { + foreach (Arr::wrap($tasks) as $task) { + $this->processFactory->path(base_path())->env([ + 'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)), + ])->run($command.' 2>&1 &'); + } + }); } }