Laravel 任务调度
步骤:
1、写好commands文件
2、在kernel当中的commands属性和schedule中增加新的脚本文件命令:
protected $commands = [
'App\Console\Commands\实例1',
'App\Console\Commands\实例2',
];
protected function schedule(Schedule $schedule)
{
$schedule->command('artisan_crawl_wangyi')->everyTenMinutes()->runInBackground();;
$schedule->command('artisan_crawl_wzutu')->everyTenMinutes()->runInBackground();;
}
最后一步、在项目中crontab -e ,会出现vim弹框,加入下面的话:*/10 * * * * php /项目路径/artisan schedule:run >> /dev/null 2>&1
注:其中的/10代表每十分钟执行一次,五个号依次为,分钟,小时,月,年,星期
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: