3
3
namespace Illuminate \Concurrency ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Console \Application ;
6
7
use Illuminate \Contracts \Concurrency \Driver ;
7
8
use Illuminate \Foundation \Defer \DeferredCallback ;
8
9
use Illuminate \Process \Factory as ProcessFactory ;
9
10
use Illuminate \Process \Pool ;
10
11
use Illuminate \Support \Arr ;
11
12
use Laravel \SerializableClosure \SerializableClosure ;
12
- use Symfony \Component \Process \PhpExecutableFinder ;
13
13
14
14
class ProcessDriver implements Driver
15
15
{
@@ -26,18 +26,13 @@ public function __construct(protected ProcessFactory $processFactory)
26
26
*/
27
27
public function run (Closure |array $ tasks ): array
28
28
{
29
- $ php = $ this ->phpBinary ();
30
- $ artisan = $ this ->artisanBinary ();
29
+ $ command = Application::formatCommandString ('invoke-serialized-closure ' );
31
30
32
- $ results = $ this ->processFactory ->pool (function (Pool $ pool ) use ($ tasks , $ php , $ artisan ) {
31
+ $ results = $ this ->processFactory ->pool (function (Pool $ pool ) use ($ tasks , $ command ) {
33
32
foreach (Arr::wrap ($ tasks ) as $ task ) {
34
33
$ pool ->path (base_path ())->env ([
35
34
'LARAVEL_INVOKABLE_CLOSURE ' => serialize (new SerializableClosure ($ task )),
36
- ])->command ([
37
- $ php ,
38
- $ artisan ,
39
- 'invoke-serialized-closure ' ,
40
- ]);
35
+ ])->command ($ command );
41
36
}
42
37
})->start ()->wait ();
43
38
@@ -59,22 +54,14 @@ public function run(Closure|array $tasks): array
59
54
*/
60
55
public function defer (Closure |array $ tasks ): DeferredCallback
61
56
{
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 ' );
72
58
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
+ });
79
66
}
80
67
}
0 commit comments