Hi in this article let's see how we can quickly set up Supervisor for Laravel Queue scheduling in Ubuntu server.
.env
ConfigurationLaravel 5.7 & above
QUEUE_CONNECTION=database
Laravel below 5.7
QUEUE_DRIVER=database
The following command will create the jobs
table to keep track of your queues.
php artisan queue:table
php artisan migrate
You might have some code to send mail like below. Make sure to implement ShouldQueue Interface
use Illuminate\Contracts\Queue\ShouldQueue;
class UserChangedPasswordMail extends Mailable implements ShouldQueue
{
...
}
Run the following command to test if the queues are working or not in your localhost or development environment
php artisan queue:listen
First, update your Ubuntu server for new package updates & then install Supervisor
.
sudo apt-get update
sudo apt install supervisor
Thinking that your project is deployed in the following path in the Ubuntu server
/var/www/html/YOUR_PROJECT
Your Supervisor configurations can be created in the following path. You can create as many as configurations for single or multiple projects.
NOTE:queue-worker.conf
is the name of the configuration file. You can rename it to anything. But make sure to keep theconf
cd /etc/supervisor/conf.d/
nano queue-worker.conf
Add the following code in queue-worker.conf
[program:queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/YOUR_PROJECT/artisan queue:work --sleep=3 --tries=5
autostart=true
autorestart=true
user=root
numprocs=4
redirect_stderr=true
stdout_logfile=/var/log/supervisor/worker.log
stopwaitsecs=3600
Make sure to add the configuration file name without .conf in the following line
[program:queue-worker]
In the following (replace YOUR_PROJECT with the name of your project)
command=php /var/www/html/YOUR_PROJECT/artisan queue:work --sleep=3 --tries=5
Run the following commands to make the new configurations take to affect
#Read the new configuration file
sudo supervisorctl reread
#Update the process of supervisor to use the new configuration
sudo supervisorctl update
#Start the process queue-worker in this case make sure to replace this
sudo supervisorctl start queue-worker
#Reload the configuration to take effect
sudo supervisorctl reload
#Restart the supervisor service
sudo service supervisor restart
#Check the status of supervisorctl
sudo supervisorctl status
#Stop all supervisor processes
sudo supervisorctl stop all
#Start all supervisor processes
sudo supervisorctl start all
#Read the new configuration file
sudo supervisorctl reread
#Update the process of supervisor to use the new configuration
sudo supervisorctl update
#Start the process queue-worker in this case make sure to replace this
sudo supervisorctl start queue-worker
#Reload the configuration to take effect
sudo supervisorctl reload
#Restart the supervisor service
sudo service supervisor restart
GitHub Login With PHP Laravel Socialite
What Is Method Chaining In PHP?
Upload File From Frontend Server {GuzzleHttp} To REST API Server In PHP {Laravel}
Generate RSS Feeds in PHP Laravel
Securely Connect Server MYSQL DB From Sequel Pro / MYSQL Workbench
Free Live Chat Integration Using TAWK.IO
Laravel Last Executed Query In Plain SQL Statement For Debugging
Run Raw Queries Securely In Laravel
Install Letsencrypt SSL Certificate for RabbitMQ Server and RabbitMQ Management Tool
Website Speed and Performance Optimizations
URL Redirects From Called Functions In Laravel
Make Laravel Controllers Slim By Skimming Form Validation Request