Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

How to schedule commands to run every few seconds in a Laravel app

Original – by Freek Van der Herten – 1 minute read

Using our spatie/laravel-short-schedule package you can schedule commands at sub-minute intervals.

// in app\Console\Kernel.php

protected function shortSchedule(\Spatie\ShortSchedule\ShortSchedule $shortSchedule)
{
    // this command will run every second
    $shortSchedule->command('artisan-command')->everySecond();
    
    // this command will run every 30 seconds
    $shortSchedule->command('another-artisan-command')->everySeconds(30);
    
    // this command will run every half a second
    $shortSchedule->command('another-artisan-command')->everySeconds(0.5);
}

In this video, I show you how you can use the package.

I've also recorded another video that shows how the package works under the hood (spoiler: we'll use ReactPHP).

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "How to schedule commands to run every few seconds in a Laravel app"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.