Laravel implementation method for automatically running scheduled tasks
P粉412533525
P粉412533525 2023-09-07 17:18:23
0
1
566

I am new to Laravel and I need to delete expired OTPs in my OTP database, I created an expires file and defined everything, when I use the php artisan schedule:run command , it works perfectly.

This is the output:

2022-09-17 16:37:15 在后台运行 ['artisan' Otp:expire] .......................................... 7ms 完成
  ⇂ ('/usr/bin/php8.1' 'artisan' Otp:expire > '/dev/null' 2>&1 ; '/usr/bin/php8.1' 'artisan' schedule:finish "framework/schedule-7ff27dde37314470633aef84f65f27b83fd05b4e" "$?") > '/dev/null' 2>&1 &

But when I run the server with php artisan serve and add an OTP, the OTP is not deleted after the expected time, it is deleted only when I use schedule run.

Please help, thank you!

P粉412533525
P粉412533525

reply all(1)
P粉478445671

Official Laravel Documentation It is recommended to use cron (Cronjob, etc.) to run the php artisan schedule:run command every minute. You can do this via the following cron entry:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template