Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handled Concurrency run() fails when passing an array instead of a cl… #54947

Draft
wants to merge 1 commit into
base: 12.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})),
]));
Expand Down
22 changes: 20 additions & 2 deletions src/Illuminate/Concurrency/ProcessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 &');
}
});
Expand Down
Loading