Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queue:push() being processed synchronously in Laravel 5

Tags:

php

queue

laravel

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?

like image 766
Anthony Avatar asked Dec 25 '22 21:12

Anthony


1 Answers

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.

like image 156
Bogdan Avatar answered Jan 17 '23 23:01

Bogdan