1、php artisan make:command Test
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'insert Test table some test data';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//需要执行的方法写在handle中
Log::info('123');
}
注册路由命令调整kernel.php文件
路径:app\console\kernel.php
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//引入定时任务文件
\App\Console\Commands\test::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//command里面写定时任务的$signature的值
$schedule->command('test')
->everyMinute();
}
设定定时任务时间
->cron('* * * * *'); 在自定义Cron调度上运行任务
->everyMinute(); 每分钟运行一次任务
->everyFiveMinutes(); 每五分钟运行一次任务
->everyTenMinutes(); 每十分钟运行一次任务
->everyThirtyMinutes(); 每三十分钟运行一次任务
->hourly(); 每小时运行一次任务
->daily(); 每天凌晨零点运行任务
->dailyAt('13:00'); 每天13:00运行任务
->twiceDaily(1, 13); 每天1:00 & 13:00运行任务
->weekly(); 每周运行一次任务
->monthly(); 每月运行一次任务
->monthlyOn(4, '15:00'); 每月4号15:00运行一次任务
->quarterly(); 每个季度运行一次
->yearly(); 每年运行一次
->timezone('America/New_York'); 设置时区
宝塔设置
脚本内容写规则:php路径 文件路径/artisan schedule:run >> /dev/null 2>&1
例如:/www/server/php/72/bin/php /www/wwwroot/ceshi/artisan schedule:run >> /dev/null 2>&1