17

I'm running Laravel 5 on Heroku. I'm using the Laravel Queue for background tasks. What is/are the most reliable ways to listen to the queue and run it's jobs?

4 Answers 4

17

Update: Deprecation notice

php artisan queue:work -h

--daemon    Run the worker in daemon mode (Deprecated)

Running queue:work spawns a daemon automatically. The flag is no longer required.


For me, it worked using Redis as the queue driver and setting up a queue worker process additionally to the web process.

My Procfile then looks like this:

web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:work redis --sleep=3 --tries=3 --daemon

I don't really know if this is the way one should go, but it works for now.

Edit:

Note, that you are starting up another dyno here, so if you are not using the free tier on Heroku it's double the price now.

2
  • 1
    Is the --deamon mode working well for you on Heroku?
    – Till
    Jul 18, 2016 at 22:23
  • 1
    @Till yes it does. what problems do you have with it?
    – eneskaya
    Jul 20, 2016 at 10:06
11

Set config var in heroku like this (Laravel 5.6):

QUEUE_DRIVER=database

Or set config var in heroku like this (Laravel 5.7):

QUEUE_CONNECTION=database

To start the worker dyno in case it is not running

heroku ps:scale worker=1

Procfile looks like this: Note: specify the driver you want to use after queue:work

web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:restart && php artisan queue:work database --tries=3

To view messages from the worker

heroku logs --ps worker

To tail messages from the worker

heroku logs --tail --ps worker
2
  • 1
    Why do you specify QUEUE_CONNECTION if you pass it as parameter to queue:work?
    – Alex P.
    Oct 23, 2019 at 21:06
  • 2
    Ah, I figured out, it is needed for dispatch calls in the code.
    – Alex P.
    Oct 24, 2019 at 8:54
2

If you are on the free plan on Heroku quite easy to get the worker process running for processing your queued items

To make sure you have both the worker and web dynos running

heroku ps:scale

To start the worker dyno in case it is not running

heroku ps:scale worker=1

Proc file looks like this:

worker: php artisan queue:restart && php artisan queue:work --tries=3

To view messages from the worker

heroku logs --ps worker
1

I have found running the Queue Worker as a daemon Laravel docs works well when used with supervisord supervisor docs which will watch the process and restart it if it should fail for any reason.

Laravel Forge supports this out of the box and provides you with a GUI to setup the daemon and supervisor tasks, if that's something you'd prefer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.