laravel 定时任务
生活随笔
收集整理的這篇文章主要介紹了
laravel 定时任务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
laravel 5開始新增了?Laravel Schedule 這個特性,方便開發者可以快速方便的利用此功能來開發自己的定時任務功能,打開?app/Console/Kernel.php :
protected function schedule(Schedule $schedule) {// $schedule->command('inspire')// ->hourly(); }1、開始創建任務:
php artisan make:console LogInfo2、在app/console就會看到LogInfo.php
3、需要執行的方法寫在handle中
4、注冊路由命令
5、在schedule方法中定義執行時間,可以是指定的時間,也可以是每分、每時、每天,Laravel 提供了諸多的方法來控制任務執行的時間間隔
$schedule->command('foo')->everyFiveMinutes();$schedule->command('foo')->everyTenMinutes();$schedule->command('foo')->everyThirtyMinutes();$schedule->command('foo')->mondays();$schedule->command('foo')->tuesdays();$schedule->command('foo')->wednesdays();$schedule->command('foo')->thursdays();$schedule->command('foo')->fridays();$schedule->command('foo')->saturdays();$schedule->command('foo')->sundays();6、到命令行輸入?php artisan schedule:run 即可執行任務
7、要實現定時任務還得讓程序自動執行
crontab -e #加入 * * * * * php /path/to/artisan schedule:run #保存最后重啟 linux 的 crond 就可以了。
總結
以上是生活随笔為你收集整理的laravel 定时任务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 抖音生活服务发布探店规范,打击“霸王餐”
- 下一篇: Laravel db:seed 报错 [