I'm running Laravel 5 and I'm trying to get queue a command. I'm kicking it off by running:
Queue::push( new MyCommand() );
To create I command, I did:
php artisan make:command --queued MyCommand
MyCommand contains a sleep(20)
and file_put_contents('test.txt','I work!')
Command-line I'm running:
beanstalkd -l 127.0.0.1 -p 11301 &
php artisan queue:listen &
And config/queue.php is set to:
'default' => env('QUEUE_DRIVER', 'beanstalkd'),
...
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost:11301',
'queue' => 'default',
'ttr' => 60,
],
When I hit the code from the browser, it hangs for 20 seconds and drops the file before completing, instead of returning immediately.
Is there something else I need to do to properly queue a command in the background?
Make sure, you don't have any QUEUE_DRIVER
value other than beanstalkd
set in the .env
file. The env()
method:
'default' => env('QUEUE_DRIVER', 'beanstalkd'),
will first search for that key in the current eviroment loaded variables, and if there are no matches, it will fallback to the beanstalkd
value passed as the second parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With