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

wassy83's avatar

avoid overlapping of different scheduled commands

I have something like this in my kernel.php

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('command:richiesta')
            ->everyThirtyMinutes()
            ->unlessBetween('17:25','20:35')
            ->withoutOverlapping();
        
        $schedule->command('command:RenewOption')
            ->everyFifteenMinutes()
            ->between('17:30','20:30')
            ->withoutOverlapping();
    }

The "richiesta" command takes around one minute to end his stuffs, instead the "RenewOption" command could take 0-15 minutes to a couple of hours. Because both "richiesta" and "RenewOption" are making a lot of parrallel curl request to an external API, I don't want them to overlap and hit the API limits, so I scheduled in a safe timing zone way. But it is a little useless to completely stop "richiesta" for 3 hours if "RenewOption" is done, or is simply not running because, in example, there is no data to fetch.

So how can I avoid the overlapping of those 2 commands without set a safe time zone? Probably some cache buffer, but I couldn't found a way to manage this.

0 likes
1 reply
christian-qode's avatar
Level 8

@wassy83 You can chain commands, so the RenewOption is started when Richiesta is done, but I'm not sure if that's what you want.

Otherwise, I'd store a value somewhere (in database or preferably in cache) on the beginning or end of the command so you can check if it's currently running.

Please or to participate in this conversation.