Scout APM is PHP application performance monitoring designed for developers. With tracing logic that ties issues back to the line of code causing them, you can pinpoint n+1 queries, memory leaks, and other abnormalities in real time so you can knock them out and get back to building a great product. Start your free 14-day trial today and get the performance insight you need in less than 4 minutes.

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.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks 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

Webmentions

Robin Dirksen liked on 4th September 2020
Luka Rasmussen liked on 4th September 2020
Roman Pronskiy liked on 4th September 2020
Tyroga liked on 4th September 2020
Tahseen 🇮🇶 liked on 3rd September 2020
Niels liked on 3rd September 2020
Spatie retweeted on 3rd September 2020
Derick Alangi 🕯 liked on 3rd September 2020
Derick Alangi 🕯 retweeted on 3rd September 2020
YB liked on 3rd September 2020
Abrar Ahmad liked on 3rd September 2020
Jackpump liked on 3rd September 2020
Nick Ciske liked on 3rd September 2020
oluwajubelo loves VueJS 🚨 liked on 3rd September 2020
Aniket Mahadik liked on 3rd September 2020
Tauseef shah liked on 3rd September 2020
Prince John Santillan liked on 3rd September 2020
Luigi Cruz liked on 3rd September 2020
Gianluca Bine liked on 3rd September 2020
Florian Voutzinos ⚡ liked on 3rd September 2020
Haz liked on 3rd September 2020
iLyas Farawe liked on 3rd September 2020
Bilal Khan liked on 3rd September 2020
Koussay liked on 3rd September 2020
Bilal Khan retweeted on 3rd September 2020