Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ga46's avatar
Level 1

How to run schedule every 7 minutes.

my current schedule runs everyFiveMinutes .

$schedule->command('b2buhrenApi:productSync')->everyFiveMinutes();
0 likes
11 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Give it the cron directly

$schedule->command('b2buhrenApi:productSync')->cron('*/7 * * * *');
2 likes
SilenceBringer's avatar

just 1 note here: it will run the task at *:56 minutes, and next one will be at :00 (4 minutes instead of 7), because 7 is not a divisor of 60.

2 likes
enadabuzaid's avatar

I mean In general you can use this function and I but the documentation link to read more about it

thank you for that :) @Sinnbeck

haheap's avatar

As others have pointed out, there is no direct way to do that in the scheduler.

If the 7 minute interval is vital, then you would have to have some sort of indication for your code to know when the scheduled job was last started - so basically a db field like last_run_at. Then run the scheduler every minute and check if it's been 7 minutes or more.

But what is the use case? There are possibly other and better ways to achieve what you're trying to achieve. :-)

ahmet_ozisik's avatar

You can run your command every minute, and just check the elapsed time since last execution. If it's less than 7 minutes, you skip. If it's more, you run it.

$lastSynced = Cache::get('last_synced_at');
 
if ($lastSynced && $lastSynced->diffInMinutes() < 7) {
  // Skip... It's not time yet.
  return;
}

Cache::put('last_synced_at', now());

// Your code...
Snapey's avatar

@sinnbeck has the right idea. This should do it

$schedule->command('b2buhrenApi:productSync')
        ->when(intval(time()/60) % 7 ==0);

should run on every 7th minute since unix epoch

3 likes

Please or to participate in this conversation.