Laravel Supervisor process monitor

Laravel queues are good at handling multiple time consuming processes. These queues are processed by the queue worker. The supervisor is a process manager of Laravel.  It is like a process monitor for queue workers . The queue worker processes the queued jobs and runs the tasks  linked with them using the below given artisan command.

php artisan queue:work

This command will start the queue worker. It will continue until the terminal is closed or  it is stopped manually. The supervisor is a process manager used to monitor the queue workers. It will automatically start the queue worker in the background so it will restart even if the worker exits unexpectedly.  Lets see how to install supervisor for Linux.

sudo apt-get install supervisor

Then create configuration file laravel-queue-worker.conf for Laravel in /etc/supervisor/conf.d directory and type the following lines in the file.

[program:laravel-queue-worker]

 

process_name=%(program_name)s_%(process_num)02d

 

command=php /home/path/to/yoursite.com/artisan queue:work

 

autostart=true

 

autorestart=true

 

user=username

 

numprocs=3

 

redirect_stderr=true

 

stdout_logfile=/home/path/to/yoursite.com /queue-worker.log

You can change the line  numprocs=3 according to your requirements in the configuration file.

Now run the following lines to start the supervisor.

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-queue-worker:*