Laravel – How To Fix Wrong Domain in Queue Jobs

There is a tricky problem that happens when queued job tries to get the URL (via URL helper or from config) – it doesn’t seem to “notice” the .env / config app.url setting.

The reason is that somehow the queue worker misses the current environment name (might only happen if it is managed system wide via upstart or similar service).

The solution would be to include the –env flag when running queue worker like that:

php /path/to/project/artisan queue:listen --env=production

Here is an example upstart queue-listener.conf that can be put in /etc/init

description "Laravel queue listener"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

setuid www-data
setgid www-data

respawn limit 5 2

    # Start Listener
    php /path/to/project/artisan queue:listen --tries=60 --env=production
end script

It can then be started / restarted like any other process using cli (file name is the name of the process):

sudo service queue-listener status
sudo service queue-listener start
sudo service queue-listener stop
sudo service queue-listener restart

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.