
Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
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
Free SSL Certificate In cPanel With ZeroSSL & Certbot
Cache Static Files With NGINX Server
Firebase Cloud Messaging (FCM) Browser Web Push Notifications Using Javascript And PHP
Create Gmail App Password For SMTP Mails
Generate Fake Data In PHP With Faker
What Is HTTP? Different HTTP Methods And Status Codes Explained With Examples
Route Model Binding In Laravel & Change Default Column id To Another Column
Create / Save / Download PDF From Blade Template In PHP Laravel
Factory States For Clean And Fluent Laravel Testing
Free Live Chat Integration Using TAWK.IO
What Is Composer? How Does It Work? Useful Composer Commands And Usage