Skip to content

Commit 6a547e4

Browse files
[11.x] Fix PHP and Artisan binary (#52744)
* fix php and artisan binary * formatting * force re-run tests * formatting * formatting * formatting * formatting * Revert "formatting" This reverts commit 4d53aa9. * require illuminate/console * Reapply "formatting" This reverts commit ddc3264. * Revert "require illuminate/console" This reverts commit b55e773.
1 parent 0ecdd71 commit 6a547e4

File tree

7 files changed

+40
-17
lines changed

7 files changed

+40
-17
lines changed

src/Illuminate/Concurrency/ProcessDriver.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ public function __construct(protected ProcessFactory $processFactory)
2525
*/
2626
public function run(Closure|array $tasks): array
2727
{
28-
$php = (new PhpExecutableFinder)->find(false);
28+
$php = $this->phpBinary();
29+
$artisan = $this->artisanBinary();
2930

30-
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php) {
31+
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php, $artisan) {
3132
foreach (Arr::wrap($tasks) as $task) {
3233
$pool->path(base_path())->env([
3334
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
34-
])->command($php.' artisan invoke-serialized-closure');
35+
])->command([
36+
$php,
37+
$artisan,
38+
'invoke-serialized-closure',
39+
]);
3540
}
3641
})->start()->wait();
3742

@@ -53,12 +58,35 @@ public function run(Closure|array $tasks): array
5358
*/
5459
public function defer(Closure|array $tasks): DeferredCallback
5560
{
56-
return defer(function () use ($tasks) {
61+
$php = $this->phpBinary();
62+
$artisan = $this->artisanBinary();
63+
64+
return defer(function () use ($tasks, $php, $artisan) {
5765
foreach (Arr::wrap($tasks) as $task) {
5866
$this->processFactory->path(base_path())->env([
5967
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
60-
])->run('php artisan invoke-serialized-closure 2>&1 &');
68+
])->run([
69+
$php,
70+
$artisan,
71+
'invoke-serialized-closure 2>&1 &',
72+
]);
6173
}
6274
});
6375
}
76+
77+
/**
78+
* Get the PHP binary.
79+
*/
80+
protected function phpBinary(): string
81+
{
82+
return (new PhpExecutableFinder)->find(false) ?: 'php';
83+
}
84+
85+
/**
86+
* Get the Artisan binary.
87+
*/
88+
protected function artisanBinary(): string
89+
{
90+
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
91+
}
6492
}

src/Illuminate/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(Container $laravel, Dispatcher $events, $version)
8484
*/
8585
public static function phpBinary()
8686
{
87-
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
87+
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false) ?: 'php');
8888
}
8989

9090
/**

src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Console\Scheduling;
44

5+
use Illuminate\Console\Application;
56
use Illuminate\Console\Command;
67
use Illuminate\Support\Carbon;
78
use Illuminate\Support\ProcessUtils;
@@ -40,11 +41,7 @@ public function handle()
4041

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

43-
$command = implode(' ', array_map(fn ($arg) => ProcessUtils::escapeArgument($arg), [
44-
PHP_BINARY,
45-
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
46-
'schedule:run',
47-
]));
44+
$command = Application::formatCommandString('schedule:run');
4845

4946
if ($this->option('run-output-file')) {
5047
$command .= ' >> '.ProcessUtils::escapeArgument($this->option('run-output-file')).' 2>&1';

src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ protected function installReverb()
154154
'laravel/reverb:^1.0',
155155
]);
156156

157-
$php = (new PhpExecutableFinder())->find(false) ?: 'php';
158-
159157
Process::run([
160-
$php,
158+
(new PhpExecutableFinder())->find(false) ?: 'php',
161159
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
162160
'reverb:install',
163161
]);

src/Illuminate/Foundation/Console/ServeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected function serverCommand()
178178
: __DIR__.'/../resources/server.php';
179179

180180
return [
181-
(new PhpExecutableFinder)->find(false),
181+
(new PhpExecutableFinder)->find(false) ?: 'php',
182182
'-S',
183183
$this->host().':'.$this->port(),
184184
$server,

src/Illuminate/Queue/Listener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct($commandPath)
6161
*/
6262
protected function phpBinary()
6363
{
64-
return (new PhpExecutableFinder)->find(false);
64+
return (new PhpExecutableFinder)->find(false) ?: 'php';
6565
}
6666

6767
/**

src/Illuminate/Support/Composer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected function findComposerFile()
204204
*/
205205
protected function phpBinary()
206206
{
207-
return (string) (new PhpExecutableFinder)->find(false);
207+
return (new PhpExecutableFinder)->find(false) ?: 'php';
208208
}
209209

210210
/**

0 commit comments

Comments
 (0)