Laravel queues gives us an excellent way to increase web application performance.
If you are using Laravel queues into your project then you have taken a good step towards the improvements of your application speed.
If your are not using Laravel queues then you should implement and use it, Queues are very useful when handling events, sending emails and process big amount of load behind the seen.
Anyways, In this tutorial I am going to provide steps on how you should handle your queues processes and monitor those on Linux operating system.
Please take a note I am going to use ubuntu 16.04 through the steps.
In Linux we have available great system package called supervisor, it is actually a great software package to monitor and control multiple process.
Okay so let’s get started from installation:
Recommended – How to Create Configure and Use Laravel Custom middleware in Laravel 5.8
Supervisor Installation in Linux:
If you have your production server running with linux operating system on VPS, then go ahed and login on to the server with root access.
Make sure you have root access available before proceeding, if you don’t have sudo/root access then system won’t allow you to install software.
To install supervisor use following command:
$ sudo apt-get update && sudo apt-get install supervisor
After executing above command, it will ask you for the confirmation of supervisor package installation, type y and hit enter to continue, as showing below:
Now we are done with the installation, next let’s configure supervisor to work on the project processes.
Supervisor Configuration (configuring laravel queue)
Take a note of path of your project directory on server where currently Laravel project is running, for example path can be /var/www/example.com/
Next let’s create new config file for supervisor using following command:
$ sudo nano /etc/supervisor/conf.d/example_project_queue.conf
You can change the file name/queue name according to your preference or project name.
Use following configuration script and add into the example_project_queue.conf file.
Make sure to update your project path according to your actual project path on server.
[program:example_project_queue] process_name=%(program_name)s_%(process_num)02d command=php /var/www/example.com/artisan queue:work database --sleep=3 --tries=3 autostart=true autorestart=true user=root numprocs=8 redirect_stderr=true stdout_logfile=/var/www/example.com/logs/worker.log
Also create an log file for supervisor as we have mention above into the configuration:
$ touch /var/www/example.com/logs/worker.log
Next will have to the start the newly added supervisor program using following commands:
$ sudo supervisorctl reread
It should show you: example_project_queue: available if yes then execute following command, if not then you must get an error message about paths if you had any mistake in there.
If you do then re-open configuration file and correct those mistakes and follow reread command again and then the following command:
$ sudo supervisorctl update
The above command should list a message: example_project_queue: added process group
If you get the above message then great, you have configured process handling for your Laravel project.
If you still see any issues, then you can comment your question or issue below into the comment box.