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