php任务调度中心,laravel 任务调度(定时执行任务)

任务调度写在  app/Console/Kernel.PHP 文件 schedule中,里面默认有一个例子。在 schedule 方法里放入自己的执行的代码。比如

这个是每一分钟在数据库里插入一条数据。

[html]<?php

namespace 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

此时显示

f081dd61c99e8231f3dc45be81a398c3.png

出现这样的界面,就是进入crontab里面了,接着

在最下面写入* * * * * php 项目的路径/artisan schedule:run >> /dev/null 2>&1按下 Ctrl + X 保存退出这样就OK ,如果不执行,请下检查代码,以及项目的路径是否正确。

本文出自 “李世龙” 博客,谢绝转载!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值