Laravel Task Scheduling Every X Hours
Asked Answered
B

3

26

I undestand that you can create hourly tasks on Laravel by using:

$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.

Bloodmobile answered 15/3, 2017 at 2:14 Comment(0)
H
66

You've tagged your question as Laravel 4, but I don't think the scheduler was introduced until Laravel 5...

Anyway, based on the code snippet you've posted, you could use the cron method.

$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

Handicap answered 15/3, 2017 at 2:24 Comment(2)
I just fixed the tag. sorry about that. Is that for Laravel 5? So in crobtab * * * * * php /path/to//artisan schedule:run >> /dev/null 2>&1 again?Bloodmobile
Thanks a lot... :)Bloodmobile
R
2

From Laravel 7 By Defalut you can give like this

$schedule->command('catalog:update')->everyTwoHours();
$schedule->command('catalog:update')->everyFiveHours();

See Docs:https://laravel.com/docs/7.x/scheduling

Reo answered 3/3, 2022 at 12:34 Comment(0)
P
0

Laravel scheduling hours cron-command can only run a task every 2 hours, 3 hours, 4 hours and 6 hours.There is no everyFiveHours() command you will have to use the cron command for 5 hours, cron('0 */5 * * *').

Below commands are supported:

->everyTwoHours();  
->everyThreeHours();    
->everyFourHours(); 
->everySixHours();  
Pomona answered 16/12, 2022 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.