Laravel 任务每 X 小时调度一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42799953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Task Scheduling Every X Hours
提问by senty
I undestand that you can create hourly tasks on Laravel by using:
我不明白您可以使用以下方法在 Laravel 上创建每小时任务:
$schedule->command('catalog:update')->hourly();
$schedule->command('catalog:update')->hourly();
however is there a way to do for example every 2 hours or 5 hours? I couldn't find it on documentation or here.
但是有没有办法做到例如每 2 小时或 5 小时一次?我在文档或这里找不到它。
回答by fubar
You've tagged your question as Laravel 4, but I don't think the scheduler was introduced until Laravel 5...
您已将您的问题标记为 Laravel 4,但我认为直到 Laravel 5 才引入调度程序...
Anyway, based on the code snippet you've posted, you could use the cron
method.
无论如何,根据您发布的代码片段,您可以使用该cron
方法。
$schedule->command('catalog:update')->cron('0 */2 * * *'); // every 2 hours
$schedule->command('catalog:update')->cron('0 */5 * * *'); // every 5 hours
See the docs for other options. https://laravel.com/docs/5.4/scheduling#defining-schedules
有关其他选项,请参阅文档。https://laravel.com/docs/5.4/scheduling#defining-schedules