Cấu hình Supervisor trong laravel

04/01/2022   Laravel
1. Use Crontab
- For schedule you should go for cronjob, you can use crontab
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
=> every minute, cmd php artisan schedule:run will run only time, will evaluate all of your scheduled tasks and determine if they need to run based on the server's current time.
2. Use Supervisor
- but if you insist to use supervisor
:
- you should use php artisan schedule:work, t
his command will run in the foreground and invoke the scheduler every minute.
For schedule you should go for cronjob, you can use crontab
but if you insist to use supervisor
follow me:
you should use php artisan schedule:work
not php artisan schedule:run
because the run command will run it just one time.
my supervisor configuration for the schedule is working well so I want to share it here:
---------------------------
[program:laravel-worker-nordicstandard-schedule]
process_name=%(program_name)s_%(process_num)02d
directory=/home/nordicstandard.net/
command=php artisan schedule:work
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile= /home/nordicstandard.net/storage/logs/worker1.log
----------------------------
- remember to use directory=/home/nordicstandard.net/
to your project folder.
- And that's it. it's working...
- in sudo supervisorctl
-> status
you can see the output like:
---------------------------------------------------
laravel-worker-nordicstandard-schedule:laravel-worker-nordicstandard-schedule_00 RUNNING pid 4084, uptime 0:06:55
----------------------------
- and this line is related to the schedule
and the others are related to the queue
.
* note: you should be careful about numprocs=1
and it shouldn't be more than one. (numprocs is number of process)

