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

[11.x] Fix PHP and Artisan binary #52744

Merged
merged 11 commits into from
Sep 12, 2024
38 changes: 33 additions & 5 deletions src/Illuminate/Concurrency/ProcessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ public function __construct(protected ProcessFactory $processFactory)
*/
public function run(Closure|array $tasks): array
{
$php = (new PhpExecutableFinder)->find(false);
$php = $this->phpBinary();
$artisan = $this->artisanBinary();

$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php) {
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php, $artisan) {
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([
$php,
$artisan,
'invoke-serialized-closure',
]);
}
})->start()->wait();

Expand All @@ -53,12 +58,35 @@ public function run(Closure|array $tasks): array
*/
public function defer(Closure|array $tasks): DeferredCallback
{
return defer(function () use ($tasks) {
$php = $this->phpBinary();
$artisan = $this->artisanBinary();

return defer(function () use ($tasks, $php, $artisan) {
foreach (Arr::wrap($tasks) as $task) {
$this->processFactory->path(base_path())->env([
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
])->run('php artisan invoke-serialized-closure 2>&1 &');
])->run([
$php,
$artisan,
'invoke-serialized-closure 2>&1 &',
]);
}
});
}

/**
* Get the PHP binary.
*/
protected function phpBinary(): string
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
}

/**
* Get the Artisan binary.
*/
protected function artisanBinary(): string
{
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(Container $laravel, Dispatcher $events, $version)
*/
public static function phpBinary()
{
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false) ?: 'php');
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Console\Scheduling;

use Illuminate\Console\Application;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\ProcessUtils;
Expand Down Expand Up @@ -40,11 +41,7 @@ public function handle()

[$lastExecutionStartedAt, $executions] = [Carbon::now()->subMinutes(10), []];

$command = implode(' ', array_map(fn ($arg) => ProcessUtils::escapeArgument($arg), [
PHP_BINARY,
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
'schedule:run',
]));
$command = Application::formatCommandString('schedule:run');

if ($this->option('run-output-file')) {
$command .= ' >> '.ProcessUtils::escapeArgument($this->option('run-output-file')).' 2>&1';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ protected function installReverb()
'laravel/reverb:^1.0',
]);

$php = (new PhpExecutableFinder())->find(false) ?: 'php';

Process::run([
$php,
(new PhpExecutableFinder())->find(false) ?: 'php',
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
'reverb:install',
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function serverCommand()
: __DIR__.'/../resources/server.php';

return [
(new PhpExecutableFinder)->find(false),
(new PhpExecutableFinder)->find(false) ?: 'php',
'-S',
$this->host().':'.$this->port(),
$server,
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($commandPath)
*/
protected function phpBinary()
{
return (new PhpExecutableFinder)->find(false);
return (new PhpExecutableFinder)->find(false) ?: 'php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function findComposerFile()
*/
protected function phpBinary()
{
return (string) (new PhpExecutableFinder)->find(false);
return (new PhpExecutableFinder)->find(false) ?: 'php';
}

/**
Expand Down