Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 77716f9

Browse files
committed
Merge pull request #17 from GrahamCampbell/env
More robust environment support
2 parents 805eb76 + 4f06811 commit 77716f9

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"php": ">=5.3.0",
1212
"illuminate/support": "~4.0",
1313
"illuminate/console": "~4.0",
14+
"sebastian/environment": "~1.0",
1415
"symfony/process": "~2.3"
1516
},
1617
"autoload": {

src/AsyncQueue.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Barryvdh\Queue\Models\Job;
66
use Illuminate\Queue\Queue;
77
use Illuminate\Queue\QueueInterface;
8+
use SebastianBergmann\Environment\Runtime;
89
use Symfony\Component\Process\Process;
910

1011
class AsyncQueue extends Queue implements QueueInterface
@@ -59,18 +60,45 @@ public function storeJob($job, $data, $delay = 0)
5960
*/
6061
public function startProcess($jobId)
6162
{
62-
$environment = $this->container->environment();
63+
$command = $this->getCommand();
6364
$cwd = $this->container['path.base'];
64-
$string = 'php artisan queue:async %d --env=%s ';
65+
66+
$process = new Process($command, $cwd);
67+
$process->run();
68+
}
69+
70+
/**
71+
* Get the Artisan command as a string for the job id.
72+
*
73+
* @param int $jobId
74+
*
75+
* @return string
76+
*/
77+
protected function getCommand($jobId)
78+
{
79+
$string = $this->getBinary().' artisan queue:async %d --env=%s ';
80+
6581
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
6682
$string = 'start /B '.$string.' > NUL';
6783
} else {
6884
$string = 'nohup '.$string.' > /dev/null 2>&1 &';
6985
}
7086

71-
$command = sprintf($string, $jobId, $environment);
72-
$process = new Process($command, $cwd);
73-
$process->run();
87+
$environment = $this->container->environment();
88+
89+
return sprintf($string, $jobId, $environment);
90+
}
91+
92+
/**
93+
* Get the php binary path.
94+
*
95+
* @return string
96+
*/
97+
protected function getBinary()
98+
{
99+
$runtime = new Runtime();
100+
101+
return $runtime->getBinary();
74102
}
75103

76104
/**

0 commit comments

Comments
 (0)