spatie/laravel-short-schedule
Schedule Laravel Artisan commands at sub-minute intervals (every second or even fractions). Define short schedules via ShortSchedule facade or Console Kernel. Note: Laravel now supports sub-minute scheduling, so this package is largely unnecessary.
withoutOverlapping, onOneServer) are needed in older versions.Console/Kernel.php via shortSchedule() method.'command:name') and class-based commands (resolved from container).--lifetime flag to terminate workers (e.g., --lifetime=60). Neglecting this risks OOM crashes.everySeconds(0.5)) may spike CPU usage. Mitigation: Benchmark under load; consider rate-limiting.short-schedule:run process. Risk: Downtime if not configured.SIGTERM). Workaround: Use Supervisor’s stopasgroup=true.ShortSchedule facade.everySeconds(0.1)) may overwhelm the system. Validate with load tests.--lifetime be set in production? What’s the acceptable trade-off between uptime and memory usage?withoutOverlapping or onOneServer may justify adoption even in Laravel 11+.schedule()->command()->everyMinute() with runInBackground() for sub-minute precision.composer require spatie/laravel-short-schedule
/etc/supervisor/conf.d/laravel-short-schedule.conf:
[program:laravel-short-schedule]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/artisan short-schedule:run --lifetime=60
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/laravel-short-schedule.log
// app/Console/Kernel.php
protected function shortSchedule(ShortSchedule $shortSchedule) {
$shortSchedule->command('analytics:process')->everySeconds(10);
$shortSchedule->command('cache:invalidate')->everySeconds(0.5)->withoutOverlapping();
}
php artisan short-schedule:run manually to verify tasks.withoutOverlapping cautiously—test for race conditions.supervisorctl reread && supervisorctl update && supervisorctl restart laravel-short-schedule.ShortSchedule::exec() for bash scripts (e.g., exec('php script.php'))..env (e.g., environments(['production'])).everySecond()) before lower-frequency ones to avoid queueing delays.withoutOverlapping for long-running commands (e.g., database migrations).between('09:00', '17:00')) to reduce unnecessary load.everySeconds(30)) and monitor before adding more.shortSchedule() require Supervisor restarts. Mitigation: Use feature flags or blue-green deployments.--lifetime settings for each environment./var/log/laravel-short-schedule.log) for crashes or permission errors.everySeconds(1) instead of everySeconds(0.1)).--lifetime is set and Supervisor is restarting processes.php artisan short-schedule:run --verbose for real-time output.ShortScheduledTaskStarting) for observability.onOneServer tasks (single-server lock). For distributed setups:
withoutOverlapping + external locking (e.g., Redis).How can I help you explore Laravel packages today?