What is Task Scheduling in Laravel?
Task Scheduling in Laravel allows you to automate repetitive tasks such as running commands, sending emails, cleaning logs, or processing data at specific times without manually running them.
Instead of creating multiple cron jobs on the server, Laravel lets you define all scheduled tasks in one place and manage them easily.
Why Task Scheduling Is Used in Laravel
- To automate recurring tasks
- To avoid managing multiple server cron jobs
- To keep task logic inside the Laravel application
- To run tasks at specific times or intervals
Where Task Scheduling Is Defined in Laravel 12
In Laravel 12, scheduled tasks are usually defined in:
routes/console.phpThis file is the recommended place to define scheduled commands and jobs.
Example: Scheduling a Command
You can schedule an Artisan command like this:
use Illuminate\Support\Facades\Schedule;
Schedule::command('emails:send')->daily();
This command will run once every day.
What Can Be Scheduled in Laravel
- Artisan commands
- Queued jobs
- Closures (anonymous functions)
- Shell or system commands
Common Scheduling Frequencies
everyMinute()hourly()daily()weekly()monthly()cron('* * * * *')for custom timing
Preventing Task Overlap
To prevent a task from running again before the previous run finishes:
Schedule::command('reports:generate')
->hourly()
->withoutOverlapping();
Running Tasks on One Server Only
In multi-server environments, you can ensure a task runs on only one server:
Schedule::command('backup:run')
->daily()
->onOneServer();
How the Scheduler Runs
Laravel uses a single cron job to run all scheduled tasks.
Server cron entry:
* * * * * php /path-to-your-project/artisan schedule:runThis command checks every minute and runs tasks that are due.
Running Scheduler Locally (Development)
For local development, you can use:
php artisan schedule:workThis keeps the scheduler running without setting up a cron job.
Summary
Task Scheduling in Laravel provides a clean and powerful way to automate recurring tasks. Laravel 12 centralizes scheduling in the application, reduces server complexity, and offers advanced controls like overlap prevention and single-server execution.
Related Answers
Still need help?
Talk to our Laravel experts
We've handled GDPR/CCPA compliance for dozens of EU & US Laravel.
