Ubuntu16.04+crontab 定时任务不执?
crontab -l 显示任务为:
* * * * * php ~/Code/www/artisan schedule:run >> /dev/null 2>&1
Kernel代码部分为:
$schedule->command('check_article');
定时任务代码为:
$now = new Carbon('2017-06-08 00:00:00');
$day = $now->toDateString();
$tomorrow = new Carbon('2017-06-09');
$tomorrow = $tomorrow->toDateString();
$data = Article::where('ptime', '>=',$day)
->where('ptime', '<', $tomorrow)
->where('is_check', '>', 0)
->get()->toArray();
if(count($data)<=0){
$res = Article::where('ptime', '>=',$day)
->where('ptime', '<', $tomorrow)->count();
$limit = $res*0.1 < 1 ? 1: intval(round($res*0.1));
$arr = Article::where('ptime', '>=',$day)
->where('ptime', '<', $tomorrow)
->orderBy(\DB::raw('RAND()'))
->limit($limit)
->get()->pluck('id')->toArray();
Article::whereIn('id', $arr)->update(['is_check'=>1]);
}
我在命令控制台直接输入php ~/Code/www/artisan schedule:run 是可以执行的。但是crontab 的定时任务却不能执行。
推荐文章: