[英]Laravel run task every hour on 08:00, 12:00, 16:00 and 20:00, 22:00
I need schedule my task every hour on 08:00, 12:00, 16:00 and 20:00, 22:00. 我需要每小时在08:00、12:00、16:00和20:00、22:00安排任务。 How I can do it?
我该怎么办?
Now I set: 现在我设置:
$schedule->command(vkliketime::class)
->hourly()
->between('8:00', '22:00');
But this is not correct, I need run task only in times 08:00, 12:00, 16:00 and 20:00, 22:00
但这是不正确的,我只需要在
08:00, 12:00, 16:00 and 20:00, 22:00
时间运行任务
I'd create a foreach loop for this, like: 我将为此创建一个foreach循环,例如:
$hours=[“08:00”, “12:00”, “16:00”, “20:00”, “22:00”];
foreach($hours as $hour) {
$schedule->command(vkliketime::class)
->dailyAt($hour);
}
There's also a less readable option using the cron()
function. 使用
cron()
函数还有一个不太可读的选项。
$schedule
->command('vkliketime::class')
->cron('0 0 8,12,16,20,22 ? * * *');
But from what I can gather a simple loop like Zoli provided would be preferable. 但从我可以收集到的类似Zoli的简单循环来看,是更可取的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.