25

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.

senty
  • 12,385
  • 28
  • 130
  • 260

3 Answers3

62

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

fubar
  • 16,918
  • 4
  • 37
  • 43
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

sai nani
  • 45
  • 2
  • 7
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();  
elver
  • 34
  • 2