<?php
namespace AppConsole;
use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;
use IlluminateSupportFacadesDB;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
AppConsoleCommandsInspire::class,
];
/**
* Define the application's command schedule.
*
* @param IlluminateConsoleSchedulingSchedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->exec(
$schedule->call(function () {
DB::table('ceshi')->insert(['contents'=>'新的数据']);
})->everyMinute()
)->daily();
}
}
执行调度任务,添加Crontab定时任务,
用命令crontab -e 添加如下内容
* * * * * /usr/local/bin/php /usr/local/var/www/projectName/artisan schedule:run >> /dev/null 2>&1
- 1
- 2
如图:
上面命令Crontab会每分钟去调Laravel的schedule命令,然后Laravel判断执行任务。