Supervisor is a linux background process control system. It is used for running background jobs. You can use this for running different background process as worker.
For running laravel queue using Supervisor it is need to install supervisor first in linux system. I am refering Ubuntu 22.04 for this.
Step1: Install Supervisor in Ubuntu
sudo apt-get install supervisor
Step2: Check Supervisor
After successfully installed Supervisor you can check status or stop/start it
sudo systemctl stop supervisor
sudo systemctl start supervisor
sudo systemctl status supervisor
Step3: Configure Supervisor for Running Laravel Queue
After installing Supervisor you will have a new directory located in /etc/supervisor/conf.d
All supervisor configuration files should be placed inside this(/etc/supervisor/conf.d) directory for running as background process. We are going to use Supervisor for laravel;
So let’s create a new file for that.
sudo nano /etc/supervisor/conf.d/laravel-queue-project1.conf
After creating this, placed below supervisor configuration and save it. Here laravel-queue-project1.conf is self defined. You can different one according to need.
[program:laravel-queue-project1]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/project1/artisan queue:work --queue=default --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/log/laravel-queue.log
This configuration file will run laravel-queue as background process and log along with other data will be saved inside /var/log/laravel-queue.log file;
If you want to run multiple laravel projects, then just need to copy this file with new name and change configurations according to need for running multiple laravel projects.
Step4: Its time to Reload Supervisor
As we have written new supervisor configuration file. So supervisor should be reread and reloaded. This will add new configuration to process list.
sudo supervisorctl reread
sudo supervisorctl update
Step5: Start Laravel Queue
Run below command for starting laravel queue
sudo supervisorctl start laravel-queue-project1:*
It’s time to insert a new job and test it.
This blog explains how to setup super in linux and make it ready for running laravel queue. This supervisor will ensure to run all background tasks(jobs) available in jobs table. You can use jobs for multipurpose such as mail sending, big file insertion etc.
I am regularly writing in this blog https://programmingmindset.com . You enhance your skill and by visiting this website
Hope that, this post will helpful. If you think this help you, then go to my YouTube channel and subscribe it. Also follow me on github