Skip to main content
Back to packages
652 GitHub stars

spatie/laravel-short-schedule

View on GitHub

Description

Schedule artisan commands to run at a sub-minute frequency.

As the Laravel Scheduler now supports sub-minute scheduled tasks, this package is no longer needed.

Laravel's native scheduler allows you to schedule Artisan commands to run every minute.

If you need to execute something with a higher frequency, for example every second, than you've come to the right package. With laravel-short-schedule installed, you can do this:

// in your routes/console.php file
 
use Spatie\ShortSchedule\Facades\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);

Alternatively, you could add this to the shortSchedule method in your console kernel:

// 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);
 
// this command will run every second and its signature will be retrieved from command automatically
$shortSchedule->command(\Spatie\ShortSchedule\Tests\Unit\TestCommand::class)->everySecond();
}

Recent Courses on Laravel Daily