If your project is built with Laravel and you use Queues, you definitely need a professional tool to manage them. One of the best tools for this is Supervisor. In this article, you will learn very simply and practically how to install Supervisor in AlmaLinux and keep Laravel jobs running all the time.
Supervisor is a Linux program that helps us execute a series of commands or programs permanently and stably in the background.
For example, if this command is not executed in your project:
php artisan queue:work
None of the queues will be executed. No emails will be sent, no SMS messages will be sent, no scheduled tasks will be performed. In short, your project will be incomplete!
Supervisor will come and paste this command and keep it running forever.
If you have WHM or a terminal, log in to SSH with root or sudo access:
ssh your-user@your-server-ip
sudo dnf install epel-release -y
sudo dnf install supervisor -y
sudo systemctl enable supervisord
sudo systemctl start supervisord
Test the Supervisor installation
sudo systemctl status supervisord
The Supervisor configuration files are in this path, you can edit them with the nano command.
/etc/supervisord.d/
Create a file specifically for the Laravel project
sudo nano /etc/supervisord.d/laravel-worker.ini
And write the following content in it:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/your-user/your-project/artisan queue:work --sleep=3 --tries=3 --timeout=90
autostart=true
autorestart=true
user=your-user
numprocs=1
redirect_stderr=true
stdout_logfile=/home/your-user/your-project/storage/logs/laravel-worker.log
stopwaitsecs=3600
Note: Be sure to write the correct path to the project and user instead of `your-user` and `your-project`.
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:
To see the status of the jobs:
sudo supervisorctl status
If everything is OK, you should see something like this:
laravel-worker:laravel-worker_00 RUNNING pid 12345, uptime 0:00:45
Run Laravel jobs permanently with Supervisor
This way you don't have to manually run the `php artisan queue:work` command every time. Supervisor always takes care of the queues. Whenever the server restarts or the process crashes for any reason, it restarts it.
In Laravel, when you run a task (such as sending an email, invoicing, processing a file, etc.) with a delay or queue, it is called a background task. This means that the user does not have to wait, but the work is done behind the scenes.
With Supervisor installed, these background tasks are always active and are performed without the need for manual intervention.
Important and professional tips
tail -f /home/your-user/your-project/storage/logs/laravel-worker.log
If the code changes, be sure to restart it:
sudo supervisorctl restart laravel-worker:
To run multiple parallel workers, you can set `numprocs=1` to 2 or more.
So
If you want your Laravel project to be always ready and to do its work behind the scenes without any problems Well, installing and configuring Supervisor in AlmaLinux is one of the most essential tasks.
With this tutorial, you can rest assured that your Laravel jobs, pages, and even background tasks are running continuously and automatically.
جستجو
قطعا تو ذهنت سوال داری
چرا زنگ نمیزنی که برات حلش کنیم؟
اینجا میتونه شروع راه تو باشه
تماس با پشتیبان
At Bariz, we are more than just a web design and SEO team; we are a family of creatives and digital experts who combine art and technology to take businesses to the next level.
Our goal is to create unique digital experiences that are not only beautiful but impactful and result-driven.
© Copyright 2024 - bariz. All Right Reserved
پشتیبان شماره 2
آنلاین
پیامی برای نمایش وجود ندارد