Skip to content

Commit fc71e91

Browse files
authored
[11.x] Use command string instead of array on Concurrency\ProcessDriver (#52813)
* use command string instead of array * use Console/Application::formatCommandString()
1 parent 79fbf4a commit fc71e91

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/Illuminate/Concurrency/ProcessDriver.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Illuminate\Concurrency;
44

55
use Closure;
6+
use Illuminate\Console\Application;
67
use Illuminate\Contracts\Concurrency\Driver;
78
use Illuminate\Foundation\Defer\DeferredCallback;
89
use Illuminate\Process\Factory as ProcessFactory;
910
use Illuminate\Process\Pool;
1011
use Illuminate\Support\Arr;
1112
use Laravel\SerializableClosure\SerializableClosure;
12-
use Symfony\Component\Process\PhpExecutableFinder;
1313

1414
class ProcessDriver implements Driver
1515
{
@@ -26,18 +26,13 @@ public function __construct(protected ProcessFactory $processFactory)
2626
*/
2727
public function run(Closure|array $tasks): array
2828
{
29-
$php = $this->phpBinary();
30-
$artisan = $this->artisanBinary();
29+
$command = Application::formatCommandString('invoke-serialized-closure');
3130

32-
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php, $artisan) {
31+
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command) {
3332
foreach (Arr::wrap($tasks) as $task) {
3433
$pool->path(base_path())->env([
3534
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
36-
])->command([
37-
$php,
38-
$artisan,
39-
'invoke-serialized-closure',
40-
]);
35+
])->command($command);
4136
}
4237
})->start()->wait();
4338

@@ -59,22 +54,14 @@ public function run(Closure|array $tasks): array
5954
*/
6055
public function defer(Closure|array $tasks): DeferredCallback
6156
{
62-
return defer(fn () => $this->run($tasks));
63-
}
64-
65-
/**
66-
* Get the PHP binary.
67-
*/
68-
protected function phpBinary(): string
69-
{
70-
return (new PhpExecutableFinder)->find(false) ?: 'php';
71-
}
57+
$command = Application::formatCommandString('invoke-serialized-closure');
7258

73-
/**
74-
* Get the Artisan binary.
75-
*/
76-
protected function artisanBinary(): string
77-
{
78-
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
59+
return defer(function () use ($tasks, $command) {
60+
foreach (Arr::wrap($tasks) as $task) {
61+
$this->processFactory->path(base_path())->env([
62+
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
63+
])->run($command.' 2>&1 &');
64+
}
65+
});
7966
}
8067
}

0 commit comments

Comments
 (0)