laravel框架 任务调度(定时执行任务)
2017-07-11 10:42
369 查看
laravel 任务调度(定时执行任务)
任务调度写在app/Console/Kernel.PHP 文件schedule中,里面默认有一个例子。在 schedule 方法里放入自己的执行的代码。比如
这个是每一分钟在数据库里插入一条数据。[html]<?phpnamespace App\Console;use Illuminate\Console\Scheduling\Schedule;use Illuminate\Foundation\Console\Kernel as ConsoleKernel;use Illuminate\Support\Facades\DB;class Kernel extends ConsoleKernel{/*** The Artisan commands provided by your application.** @var array*/protected $commands = [\App\Console\Commands\Inspire::class,];/*** Define the application's command schedule.** @param \Illuminate\Console\Scheduling\Schedule $schedule* @return void*/protected function schedule(Schedule $schedule){$schedule->exec($schedule->call(function () {DB::table('ceshi')->insert(['contents'=>'新的数据']);})->everyMinute())->daily();}}写完了,还需要定时执行怎么办?借助Liunx的crontab 来定时执行执行,crontab -e 此时显示出现这样的界面,就是进入crontab里面了,接着在最下面写入
* * * * * php 项目的路径/artisan schedule:run >> /dev/null 2>&1
按下 Ctrl + X 保存退出
这样就OK ,如果不执行,请下检查代码,以及项目的路径是否正确。
相关文章推荐
- quartz任务调度框架实现任务定时执行,不传参的配置(一)
- 使用laravel的任务调度(定时执行任务)
- 使用laravel的任务调度(定时执行任务)
- laravel 任务调度(定时执行任务)
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 基于ASP.NET MVC(C#)和Quartz.Net组件实现的定时执行任务调度
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- C# 定时任务 调度框架 WebWork (Quartz.NET) Web版的Windows服务
- springmvc中实现quartz定时任务(每分钟的第3秒执行任务调度方法)
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- Spring整合quartz框架实现任务定时调度
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务
- 任务调度开源框架Quartz动态添加、修改和删除定时任务