spatie/laravel-cronless-schedule
Run Laravel’s scheduler without cron. This dev/test-friendly package adds php artisan schedule:run-cronless, which uses a ReactPHP loop to execute the scheduler on a timer (default every minute), with optional custom frequency and manual runs.
schedule:run with a ReactPHP-based loop, maintaining 100% compatibility with Laravel’s scheduling syntax (e.g., Schedule::command()->everyMinute()).* * * * * php artisan schedule:run with php artisan schedule:run-cronless.ext-pcntl for process management in some environments).# .github/workflows/schedule.yml
jobs:
run-scheduler:
runs-on: ubuntu-latest
steps:
- run: php artisan schedule:run-cronless &
- run: sleep 60 # Simulate 1 minute
sleep(60) in tests instead of relying on exact timing.cron.log. Instrument with Laravel’s logging or Spatie\CronlessSchedule\CronlessSchedule::log().restart: unless-stopped, or Kubernetes livenessProbe?)React\EventLoop\LoopInterface?)| Stack Component | Compatibility | Notes |
|---|---|---|
| Laravel Version | 8.x–11.x (tested) | Check composer.json for exact version constraints. |
| PHP Version | 8.0+ | ReactPHP 1.0+ required. |
| Web Server | N/A (CLI-only) | No impact on Apache/Nginx. |
| CI/CD | GitHub Actions, GitLab CI, CircleCI, etc. | Ideal for ephemeral environments. |
| Serverless | AWS Lambda, Cloudflare Workers (with PHP runtime) | Use Lambda’s timeout settings carefully (60s+ for long-running tasks). |
| Containerized | Docker, Kubernetes | Use command: ["php", "artisan", "schedule:run-cronless"] in Dockerfile. |
| Shared Hosting | cPanel, Heroku (with PHP CLI access) | Avoid if pcntl or ReactPHP is blocked. |
Replace Cron Entry:
* * * * * php artisan schedule:run from crontab.package.json (for Node.js-based setups):
"scripts": {
"schedule": "php artisan schedule:run-cronless"
}
[Service]
ExecStart=/usr/bin/php /path/to/artisan schedule:run-cronless
Restart=always
Test Locally:
php artisan schedule:run-cronless.php artisan tinker
>>> \Spatie\CronlessSchedule\CronlessSchedule::getLastRunTime();
CI/CD Integration:
- name: Run scheduler
run: php artisan schedule:run-cronless &
timeout-minutes: 1
Production (If Absolutely Necessary):
htop/docker stats for CPU/memory spikes.Schedule facade.->hourly(), ->cron(), ->command()).schedule:run-cronless alongside queue:work may cause race conditions. Solution: Use separate processes.config/app.php timezone matches server timezone.DB::transactionLevel(0).schedule:run-cronless immediately for local testing.React\EventLoop\LoopInterface in PHPUnit for unit tests:
$loop = Mockery::mock('React\EventLoop\LoopInterface');
$loop->shouldReceive('addPeriodicTimer')->andReturn(true);
$this->app->instance('reactphp', $loop);
* * * * * vs. 0 * * * *).livenessProbe).cron.log. Solution: Extend CronlessSchedule to log to Laravel’s channels.php artisan schedule:list to verify tasks.tail -f storage/logs/laravel.log.set_time_limit(0) if needed).memory_get_usage().Schedule::command('php artisan heavy:task')->onOneServer()->everyMinute().| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Process crashes | Missed schedules | Use PM2/Super |
How can I help you explore Laravel packages today?