spatie/laravel-short-schedule
Run Laravel Artisan commands at sub-minute intervals (every second or even 0.5s). Adds a short-scheduler powered by a ReactPHP event loop, running separately from schedule:run so high-frequency tasks don’t block or get delayed.
Symfony\Component\Process, preventing memory leaks or blocking the scheduler loop. This is a major advantage over Laravel’s native scheduler, which runs tasks sequentially in the foreground.between), environment-specific (environments), and conditional (when) constraints, enabling fine-grained control over execution.Console/Kernel.php via the shortSchedule() method or routes/console.php via the ShortSchedule facade.exec()), broadening use cases (e.g., calling external APIs or scripts).--lifetime flag (e.g., --lifetime=60), but requires proactive monitoring.ShortScheduledTaskStarting) run in the loop and can delay other tasks if slow. Critical: Offload heavy logic to queues.spatie/reactphp-test).delay) suffice?onOneServer()).queue:work poller with a 10-second short-schedule task.composer require spatie/laravel-short-schedule
shortSchedule() in app/Console/Kernel.php:
protected function shortSchedule(ShortSchedule $shortSchedule) {
$shortSchedule->command('telemetry:process')->everySeconds(5);
}
[program:short-schedule]
command=php artisan short-schedule:run --lifetime=300
autostart=true
autorestart=true
user=www-data
numprocs=1
php artisan my:task).ShortSchedule::exec('bash script.sh')).environments() to restrict tasks to specific environments (e.g., production only).runInMaintenanceMode()).shortSchedule() (preferred) or routes/console.php.between, when, environments) to refine execution.php artisan short-schedule:run
--lifetime if memory is a concern.--lifetime flag helps mitigate memory leaks but adds operational overhead (e.g., logging restarts).supervisorctl restart short-schedule).ShortSchedule::command('my:task')->everySecond()->listen(function ($event) {
logger()->info("Task started (PID: {$event->process->getPid()})");
});
journalctl for systemd, Supervisor logs).withoutOverlapping() to prevent concurrent runs.environments() constraints are applied correctly.How can I help you explore Laravel packages today?