Click Below to subscribe

How to Run Laravel Queue Worker on Server 2022

To keep the queue:work process running permanently in the background, we need to use a process monitor such as Supervisor to ensure that the queue worker does not stop running.

In this article, we will setup supervisor on our linux server.

1. Install Supervisor

sudo apt-get install supervisor

2.  Go to /etc/supervisor/conf.d directory.

cd /etc/supervisor/conf.d

3. Create a queue worker config and paste the worker configuration.

sudo nano mail-queue-worker.conf
[program:mail-queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-queue/artisan queue:work database --tries=3
autostart=true
autorestart=true
numprocs=2
stdout_logfile=/var/www/laravel-queue/storage/logs/mail-queue-worker.log
redirect_stderr=true
stopwaitsecs=60 

If you want to start worker for a specific queue then

[program:mail-queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-queue/artisan queue:work --queue=mailqueue database --tries=3
autostart=true
autorestart=true
numprocs=2
stdout_logfile=/var/www/laravel-queue/storage/logs/mail-queue-worker.log
redirect_stderr=true
stopwaitsecs=60 

Note:- Don't forget to create mail-queue-worker.log file inside storage/logs directory.

4.  Hit the following commands to start supervisor

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start all

5. You can also check supervisor status by hitting the following commands.

sudo supervisorctl status

Note:- Don't forget to restart the supervisor after deploying any code.

sudo supervisorctl restart all

If you facing any issues. don't hesitate to comment below. I will be happy to help you.

Leave Your Comment