diff --git a/src/Illuminate/Concurrency/Console/InvokeSerializedClosureCommand.php b/src/Illuminate/Concurrency/Console/InvokeSerializedClosureCommand.php index 15e6abe3986..b71a86ec558 100644 --- a/src/Illuminate/Concurrency/Console/InvokeSerializedClosureCommand.php +++ b/src/Illuminate/Concurrency/Console/InvokeSerializedClosureCommand.php @@ -45,7 +45,7 @@ public function handle() 'successful' => true, 'result' => serialize($this->laravel->call(match (true) { ! is_null($this->argument('code')) => unserialize($this->argument('code')), - isset($_SERVER['LARAVEL_INVOKABLE_CLOSURE']) => unserialize($_SERVER['LARAVEL_INVOKABLE_CLOSURE']), + isset($_SERVER['LARAVEL_INVOKABLE_CLOSURE']) => str_starts_with($_SERVER['LARAVEL_INVOKABLE_CLOSURE'], 'O:47:"Laravel\SerializableClosure\SerializableClosure"') ? unserialize($_SERVER['LARAVEL_INVOKABLE_CLOSURE']) : json_decode($_SERVER['LARAVEL_INVOKABLE_CLOSURE'], true), default => fn () => null, })), ])); diff --git a/src/Illuminate/Concurrency/ProcessDriver.php b/src/Illuminate/Concurrency/ProcessDriver.php index bab43e61f30..09e5a8f37fd 100644 --- a/src/Illuminate/Concurrency/ProcessDriver.php +++ b/src/Illuminate/Concurrency/ProcessDriver.php @@ -33,8 +33,17 @@ public function run(Closure|array $tasks): array $results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command) { foreach (Arr::wrap($tasks) as $key => $task) { + + // Check if the task is a closure + if ($task instanceof Closure) { + $serializedTask = serialize(new SerializableClosure($task)); + } else { + // Serialize arrays or other data as JSON + $serializedTask = json_encode($task); + } + $pool->as($key)->path(base_path())->env([ - 'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)), + 'LARAVEL_INVOKABLE_CLOSURE' => serialize($serializedTask), ])->command($command); } })->start()->wait(); @@ -67,8 +76,17 @@ public function defer(Closure|array $tasks): DeferredCallback return defer(function () use ($tasks, $command) { foreach (Arr::wrap($tasks) as $task) { + + // Check if the task is a closure + if ($task instanceof Closure) { + $serializedTask = serialize(new SerializableClosure($task)); + } else { + // Serialize arrays or other data as JSON + $serializedTask = json_encode($task); + } + $this->processFactory->path(base_path())->env([ - 'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)), + 'LARAVEL_INVOKABLE_CLOSURE' => serialize($serializedTask), ])->run($command.' 2>&1 &'); } });