11<?php
2-
32namespace Barryvdh \Queue ;
43
54use Barryvdh \Queue \Models \Job ;
65use Illuminate \Queue \Queue ;
76use Illuminate \Queue \QueueInterface ;
8- use SebastianBergmann \Environment \Runtime ;
9- use Symfony \Component \Process \Process ;
7+ use Symfony \Component \Process \PhpExecutableFinder ;
108
119class AsyncQueue extends Queue implements QueueInterface
1210{
11+ /** @var PhpExecutableFinder */
12+ protected $ phpfinder ;
13+
14+ public function __construct (){
15+ $ this ->phpfinder = new PhpExecutableFinder ();
16+ }
17+
1318 /**
1419 * Push a new job onto the queue.
1520 *
@@ -60,11 +65,8 @@ public function storeJob($job, $data, $delay = 0)
6065 */
6166 public function startProcess ($ jobId )
6267 {
63- $ command = $ this ->getCommand ($ jobId );
64- $ cwd = $ this ->container ['path.base ' ];
65-
66- $ process = new Process ($ command , $ cwd );
67- $ process ->run ();
68+ chdir ($ this ->container ['path.base ' ]);
69+ exec ($ this ->getCommand ($ jobId ));
6870 }
6971
7072 /**
@@ -76,29 +78,29 @@ public function startProcess($jobId)
7678 */
7779 protected function getCommand ($ jobId )
7880 {
79- $ string = $ this ->getBinary ().' artisan queue:async %d --env=%s ' ;
80-
81- if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
82- $ string = 'start /B ' .$ string .' > NUL ' ;
83- } else {
84- $ string = 'nohup ' .$ string .' > /dev/null 2>&1 & ' ;
85- }
81+ $ cmd = '%s artisan queue:async %d --env=%s ' ;
82+ $ cmd = $ this ->getBackgroundCommand ($ cmd );
8683
84+ $ php = $ this ->getPhpBinary ();
8785 $ environment = $ this ->container ->environment ();
8886
89- return sprintf ($ string , $ jobId , $ environment );
87+ return sprintf ($ cmd , $ php , $ jobId , $ environment );
9088 }
9189
92- /**
93- * Get the php binary path.
94- *
95- * @return string
96- */
97- protected function getBinary ()
90+ protected function getPhpBinary ()
9891 {
99- $ runtime = new Runtime ();
92+ $ path = escapeshellarg ($ this ->phpfinder ->find (false ));
93+ $ args = implode (' ' , $ this ->phpfinder ->findArguments ());
94+ return trim ($ path .' ' .$ args );
95+ }
10096
101- return $ runtime ->getBinary ();
97+ protected function getBackgroundCommand ($ cmd )
98+ {
99+ if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
100+ return 'start /B ' .$ cmd .' > NUL ' ;
101+ } else {
102+ return $ cmd .' > /dev/null 2>&1 & ' ;
103+ }
102104 }
103105
104106 /**
0 commit comments