Laravel Queue worker on Heroku

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.


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


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

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