Support the ongoing development of →

A package to schedule Artisan commands at sub-minute frequencies

24 Jun, 2020 2 min read 110 views

Laravel's native scheduler allows you to schedule Artisan commands to run every minute. For a project I'm working on I needed to schedule a command to run every few seconds. I found a good solution to do this using an ReactPHP powered event loop. Because this solution could be helpful for others as well, I decided to package it up.

Using the laravel-short-schedule package, you can schedule artisan commands to run every second or even lower frequencies. In this blogpost I'd like to introduce the package.

Scheduling commands with sub-minute frequencies

If you need to execute something with a higher frequency, you should add method named shortSchedule to app\Console\Kernel and let it accept an instance of \Spatie\ShortSchedule\ShortSchedule. Inside this method you can schedule your commands. Here's an example:

// in app\Console\Kernel.php

protected function shortSchedule(\Spatie\ShortSchedule\ShortSchedule $shortSchedule)
    // this command will run every second
    // this command will run every 30 seconds
    // this command will run every half a second

In addition to Artisan commands, you can also schedule bash commands.


By default, a scheduled command will run, even if the previous invocation is still running. You can prevent that by tacking on withoutOverlapping:


You can also add some constraints. Here the artisan command will only be executed every second between 09:00 and 17:00.

$shortSchedule->command('artisan-command')->between('09:00', '17:00')->everySecond();

How the package works under the hood

The package uses a ReactPHP event loop to schedule commands. I have recorded a video where I explain in detail how the package works, and another video where I explain how it is tested. I'm pretty sure everyone can learn something from how the package is built.

These videos are part of the Laravel Package Training. The course will teach you how to create quality packages and contains source dives of a bunch of other packes too.

Another way seeing the videos is by becoming a sponsor of Spatie. Both videos are available on the video section at

Along with those two videos, I recorded a third one that shows how the package can be used. You can see that one here:

In closing

Do you want to know more about the package? Head over to the readme on GitHub. There are a few options available, that were not mentioned in this blogpost.

This package isn't the first one my team and have built. Take a look at this long list of packages we open released previously.

Last updated 9 months ago.
Like this article? Let the author know and give them a clap!

Other articles you might like

May 22nd 2023

Console Applications With Laravel Zero

Here's a news flash: You can write console applications with Laravel! Actually, it's kinda with Lara...

Read article
January 23rd 2023

Laravel AaaS - Actions as a Service

Introduction Laravel is an amazing framework. We can build products really quick with all the featur...

Read article
January 16th 2023

Laravel Collections: The Artisan's Guide

Introduction Laravel Collections are really powerful for working with arrays of data. They provide a...

Read article

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.