Laravel scheduled tasks need to use cron; if you want to execute all laravel tasks regularly in laravel, you need to add cron entries on the server and add "phppath project path/artisan schedule:run..." to the root file. "The code is enough.
The operating environment of this article: linux7.3 system, Laravel version 5.4, Dell G3 computer.
There is a very powerful function in laravel. You only need to add a cron entry on the server to execute all laravel tasks regularly. .
Now we have the following data table:
I want the value of the cron field in the cron table to increase by 1 every minute, then I need to be as follows Steps:
1. Write laravel code in App\Console\Kernel.php
protected function schedule(Schedule $schedule) { $schedule->call(function () { DB::table('cron')->increment('cron'); })->everyMinute(); }
2. Add code to the /var/spool/cron/root file of the service
Note: It is best to use the vim editor to edit the file here. If you use winscp to edit the file, there will be a problem of not executing the task.
Enter on the command line
crontab -e
Add the following code
* * * * * /usr/local/php/bin/php /data/wwwroot/test/artisan schedule:run 1>> /dev/null 2>&1
Enter on the command line
crontab -u root -l
laravel video tutorial]
The above is the detailed content of Do laravel scheduled tasks need to use cron?. For more information, please follow other related articles on the PHP Chinese website!