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

Commit 4609f37

Browse files
committed
Tweak configuration
No auto-detection, just use the config with defaults. Detection isn't realiable. See #25 Escape php binary and add optional arguments.
1 parent a613d23 commit 4609f37

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

readme.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ You should now be able to use the async driver in config/queue.php
3434
...
3535
'async' => array(
3636
'driver' => 'async',
37-
'binary' => 'php', // Optional: path to php binary, defaults to 'php'. Set to null to autodetect.
37+
),
38+
...
39+
}
40+
41+
By default, `php` is used as the binary path to PHP. You can change this by adding the `binary` option to the queue config. You can also add extra arguments (for HHVM for example)
42+
43+
'connections' => array(
44+
...
45+
'async' => array(
46+
'driver' => 'async',
47+
'binary' => 'php',
48+
'binary_args' => '',
3849
),
3950
...
4051
}

src/AsyncQueue.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
use Barryvdh\Queue\Models\Job;
55
use Illuminate\Queue\SyncQueue;
6-
use Symfony\Component\Process\PhpExecutableFinder;
76

87
class AsyncQueue extends SyncQueue
98
{
10-
protected $binary;
9+
/** @var array */
10+
protected $config;
1111

12+
/**
13+
* @param array $config
14+
*/
1215
public function __construct(array $config)
1316
{
14-
$this->binary = array_key_exists('binary', $config) ? $config['binary'] : 'phpauto';
15-
if (!$this->binary) {
16-
$this->binary = $this->getPhpBinary();
17-
}
17+
$this->config = $config;
1818
}
1919

2020
/**
@@ -83,16 +83,24 @@ protected function getCommand($jobId)
8383
$cmd = '%s artisan queue:async %d --env=%s';
8484
$cmd = $this->getBackgroundCommand($cmd);
8585

86+
$binary = $this->getPhpBinary();
8687
$environment = $this->container->environment();
8788

88-
return sprintf($cmd, $this->binary, $jobId, $environment);
89+
return sprintf($cmd, $binary, $jobId, $environment);
8990
}
9091

92+
/**
93+
* Get the escaped PHP Binary from the configuration
94+
*
95+
* @return string
96+
*/
9197
protected function getPhpBinary()
9298
{
93-
$phpfinder = new PhpExecutableFinder();
94-
$path = escapeshellarg($phpfinder->find(false));
95-
$args = implode(' ', $phpfinder->findArguments());
99+
$path = escapeshellarg($this->config['binary']);
100+
$args = $this->config['binary_args'];
101+
if(is_array($args)){
102+
$args = implode(' ', $args);
103+
}
96104
return trim($path.' '.$args);
97105
}
98106

src/Connectors/AsyncConnector.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
class AsyncConnector implements ConnectorInterface
99
{
10+
/**
11+
* Default configuration
12+
*
13+
* @var array
14+
*/
15+
protected $defaults = array(
16+
'binary' => 'php',
17+
'binary_args' => '',
18+
);
19+
1020
/**
1121
* Establish a queue connection.
1222
*
@@ -16,6 +26,7 @@ class AsyncConnector implements ConnectorInterface
1626
*/
1727
public function connect(array $config)
1828
{
29+
$config = array_merge($this->defaults, $config);
1930
return new AsyncQueue($config);
2031
}
2132
}

0 commit comments

Comments
 (0)