Skip to content

Commit

Permalink
[11.x] Use command string instead of array on `Concurrency\ProcessDri…
Browse files Browse the repository at this point in the history
…ver` (#52813)

* use command string instead of array

* use Console/Application::formatCommandString()
  • Loading branch information
rodrigopedra authored Sep 16, 2024
1 parent 79fbf4a commit fc71e91
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/Illuminate/Concurrency/ProcessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();

Expand All @@ -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 &');
}
});
}
}

0 comments on commit fc71e91

Please sign in to comment.