Laravel’s scheduler still sits on top of cron.
You only need one cron entry.
Add the cron entry
Bash
crontab -eAdd:
Bash
* * * * * /usr/bin/php8.2 /var/www/myapp/artisan schedule:run >> /dev/null 2>&1Key points:
- Use full paths
- Redirect output unless debugging
Define scheduled tasks
Scheduled tasks live in routes/console.php.
Here’s an example:
PHP
use Illuminate\Support\Facades\Schedule;
Schedule::command('queue:restart')
->dailyAt('02:00');
Schedule::command('backup:run')
->daily()
->withoutOverlapping();
Schedule::call(function () {
CleanupJob::dispatch();
})->hourly();This keeps scheduling logic simple and close to your CLI commands.
Schedule jobs, not heavy logic
Best practice is to dispatch jobs rather than doing work directly:
PHP
Schedule::call(fn () => SyncDataJob::dispatch())
->everyTenMinutes();Cron stays fast, queues do the heavy lifting.
Prevent overlapping tasks
For anything long running
PHP
->withoutOverlapping()This relies on cache locking, so make sure cache is configured correctly.
Debugging when nothing runs
Run manually:
Bash
php artisan schedule:runIf this works but cron doesn’t, check:
- You’ve specified the right path to PHP
- That you’re using the right cron user
- Environment variables are correct and available
How this fits together
Typical production setup:
- Cron triggers scheduler
- Scheduler dispatches jobs
- Supervisor runs workers
Each tool does one job – no magic.
Leave a Reply