How to auto run schedualing in Laravel

Viewed 37

I'm new in Laravel and I need to swlwtw otps expired in my otps database, I create an expiration file and define all things, and the command runs perfectly when I use php artisan schedule:run

this is the output:

2022-09-17 16:37:15 Running ['artisan' Otp:expire] in background .......................................... 7ms DONE
  ⇂ ('/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 I add an OTP the OTP didn't be deleted after the time expected, it deletes only when I use schedule run. any help, please?

2 Answers

The official laravel documentation suggests running the php artisan schedule:run command every minute by using a cron (Cronjob etc.). You can do it by using the following cron entry:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

The best way is to use Supervisor, which runs your command constantly, and when the process finishes the new one will start immediately. If you use Cronjob, you should know that It runs every process for a minute minimum! Please check the Laravel documentation

Related