6

Using illuminate/queue outside of Laravel

Posted in PHP

I’ve been wanting to use iron.io queues with Illuminate/Queue and despite claiming otherwise in its readme, this doesn’t actually work with the provided example code – instead simply resulting in

Fatal error: Uncaught exception ‘ReflectionException’ with message ‘Class encrypter does not exist’ in /vendor/illuminate/container/Illuminate/Container/Container.php on line 485

I’ve tried numerous times to get a fix from Taylor and ignored/given the runaround every time. I even submitted a pull request with the solution but it was closed without merge or explanation.

Anyway, to ACTUALLY use iron.io with illuminate/queue outside of laravel, the following lines of code are required:

1
2
3
4
5
6
$queue->getContainer()->bind('encrypter', function() {
	return new Illuminate\Encryption\Encrypter('foobar');
});
$queue->getContainer()->bind('request', function() {
	return new Illuminate\Http\Request();
});

Drop them below $queue->addConnection and you’re good to go. Here’s complete example file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'vendor/autoload.php';
 
use Illuminate\Queue\Capsule\Manager as Queue;
use Carbon\Carbon;
 
$queue = new Queue;
 
$queue->addConnection(require __DIR__.'/config/queue.php');
 
// Make this Capsule instance available globally via static methods... (optional)
$queue->setAsGlobal();
 
$date = Carbon::now()->addMinutes(2);
$queue->getContainer()->bind('encrypter', function() {
	return new Illuminate\Encryption\Encrypter('foobar');
});
$queue->getContainer()->bind('request', function() {
	return new Illuminate\Http\Request();
});
Queue::push($date, 'EmailTest', array('foo' => 'bar'));
 
class EmailTest
{
	public function fire($job, $data)
	{
		mail('my@email.com', 'hiya', $data['foo']);
	}
}