How to create set Laravel schedule for each hour 15 minutes?

6.6k Views Asked by At

I need to run some data update functions each hours 15 minutes. For example:

  • 12:15
  • 13:15
  • 14:15
  • 15:15

How to create schedule for it? I tried something like $schedule->command('stats:refresh')->hourly()->at(':12'); but didn’t work.

5

There are 5 best solutions below

1
On

You can use

$schedule->command('command')->cron('* * * * *') 

Every star from left to right refers to

  • minute (0-59)
  • hour (0-23)
  • day of month (1-31)
  • month (1-12)
  • day of the week (0 is Sunday, 6 is Saturday)

please take look at : http://maxoffsky.com/code-blog/practical-laravel-using-cron-jobs-in-laravel/

0
On

Try something like $schedule->command('stats:refresh')->cron('15 0-23 * * * *')

Cron uses 5 asterisks as arguments. I've made a pull request, because I thought there is a mistake in Laravel documentation: https://github.com/laravel/docs/pull/2166

But here's answer from main Laravel developer:

There is an optional 6th "year" argument available: http://www.nncron.ru/help/EN/working/cron-format.htm

If you click the last link, you'll see description of which one of the six asterisks.

0
On
$schedule->command('command')->cron('15 * * * *') 
1
On

@Alexey it should be

  $schedule->command('stats:refresh')->cron('15 0-23 * * *') 

instead. If you add 15 0-23 to your asterisks it makes 6 instead of 5.

0
On

You can do like this.

...
$schedule->command('your:command')->everyFiveMinutes();
...

Hope it help you.