Today, We want to share with you Laravel Supervisor.In this post we will show you supervisor setup & configuration, hear for check if queue is running we will give you demo and example for implement.In this post, we will learn about How To Configure Supervisor For Laravel 5/6/7 Queue Jobs? with an example.
Laravel Queue worker and Supervisor process monitor
In this tutorial we learn to all about Laravel Supervisor Examples like as a Laravel Installing and setup Supervisor, start, stop, restart and update on database queue or many more.
How to setup laravel queue with database?
# add database migration tables $ php artisan queue:table # run the migration $ php artisan migrate
Installing Supervisor on Linux
sudo apt-get install supervisor
How to setup supervisor?
here step by step Supervisor configuration for Laravel
# install supervisor $ sudo apt-get install supervisor # go to supervisor config directory cd /etc/supervisor/conf.d # create a new laravel configuration $ sudo nano laravel-worker.conf # paste following some contents to our file # save changes using Ctrl + X + Y + Enter [program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /var/www/domain-name.com/artisan queue:work sqs --sleep=3 --tries=3 --daemon autostart=true autorestart=true user=forge numprocs=8 redirect_stderr=true stdout_logfile=/var/www/domain-name.com/worker.log
numprocs=8 will run 8 worker process.
Edit .conf File in Live Server
[root@ak9898 supervisord.d]# nano laravel-worker.conf
supervisor reread, update and check status
here supervisor run following command to initialize new configurations:
# read the new config $ sudo supervisorctl reread # activate our configuration $ sudo supervisorctl update # start queue command $ sudo supervisorctl start laravel-worker:* # check the status of our new config $ sudo supervisorctl status
Additional Supervisor Command
START THE PROCESSES IN SUPERVISOR
After Code changes Last Process
[root@ak9898 supervisord.d]# sudo supervisorctl start [root@ak9898 supervisord.d]# sudo supervisorctl reread [root@ak9898 supervisord.d]# sudo supervisorctl update [root@ak9898 supervisord.d]# sudo supervisorctl restart laravel-worker:* //or $ supervisorctl start all $ supervisorctl start job_worker
STOP THE PROCESSES IN SUPERVISOR
[root@ak9898 supervisord.d]# sudo supervisorctl stop
UPDATE THE PROCESSES IN SUPERVISOR
[root@ak9898 supervisord.d]# sudo supervisorctl update
RESTART THE PROCESSES IN SUPERVISOR
[root@ak9898 supervisord.d]# sudo supervisorctl reread [root@ak9898 supervisord.d]# sudo supervisorctl update [root@ak9898 supervisord.d]# sudo supervisorctl restart laravel-worker:*
Starting Supervisor
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start laravel-queue-worker:*
How to create queue in laravel?
# create a new job
$ php artisan make:job autoPostArticle
app/Jobs/autoPostArticle.php
update our article controller
dispatch( (new autoPostArticle($article))->onQueue('emails') ); } }update our job class
article = $article; } /** * Execute the job. * * @return void */ public function handle() { // your logic for notifying subscriber goes here foreach($this->article->subscribers() as $user) { // send them an email } } }Last Change
QUEUE_DRIVER=databaseI hope you get an idea about Laravel Supervisor.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.