Installation
This page covers the requirements of laravel-schedule-monitor, installing it with Composer, creating its two database tables, publishing the configuration file, and the steps every production setup needs: syncing on deploy and pruning old log items.
Requirements
The requirements come from the package's composer.json:
| Dependency | Constraint | Notes |
|---|---|---|
php |
^8.2 |
CI runs PHP 8.2 to 8.6. |
illuminate/bus |
^11.0|^12.0|^13.0 |
In practice: Laravel 11, 12, or 13. |
nesbot/carbon |
^2.63|^3.0 |
|
nunomaduro/termwind |
^2.0 |
Renders the console output of the commands. |
lorisleiva/cron-translator |
^0.3.0|^0.4.0|^0.5 |
Turns cron expressions into text such as "Every hour" in the list output. |
spatie/laravel-package-tools |
^1.9 |
The pings to Oh Dear and the Oh Dear API calls go through Laravel's HTTP client, so Guzzle must be available, as it is in a standard Laravel application. No Oh Dear SDK is needed since version 4.
Older Laravel Versions
| Laravel | Package version |
|---|---|
| 11, 12, 13 | 4.x (current) |
| 8 | 2.x: composer require spatie/laravel-schedule-monitor:^2 |
The 4.3.0 release dropped Laravel 9 and 10 and PHP 8.1. If you are upgrading from an older major version, read Upgrading.
Install the Package
composer require spatie/laravel-schedule-monitor
The service provider Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider is registered automatically through Laravel's package discovery. When it boots, it:
- registers the
schedule-monitor:list,schedule-monitor:sync, andschedule-monitor:verifycommands, - subscribes to the scheduler's task events,
- adds the
monitorName(),graceTimeInMinutes(),doNotMonitor(),doNotMonitorAtOhDear(), andstoreOutputInDb()methods to scheduled events, - binds the configured Eloquent models and checks that they extend the package's models,
- adds
PingOhDearJobto Horizon's silenced jobs when Horizon is installed (configurable).
Create the Database Tables
Publish the migration and run it:
php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations"
php artisan migrate
This creates two tables:
monitored_scheduled_tasks: one row per monitored task, with its name, type, cron expression, timezone, grace time, Oh Dear ping URL, and the timestamps of its last start, finish, failure, and skip.monitored_scheduled_task_log_items: one row per event, linked to its task with a foreign key that cascades on delete, with atypeand a JSONmetacolumn.
The full schema is described on Database and Models.
Note: The published migration has an
up()method but nodown()method, sophp artisan migrate:rollbackdoes not drop these tables. Drop them manually if you uninstall the package.
Publish the Configuration (Optional)
The package works with its defaults. Publish the config file when you want to change the retention period, date format, models, or set up Oh Dear:
php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-config"
This creates config/schedule-monitor.php. Every key is documented on Configuration. The Oh Dear settings can also be set through environment variables without publishing the file:
OH_DEAR_API_TOKEN=your-api-token
OH_DEAR_MONITOR_ID=12345
OH_DEAR_QUEUE=oh-dear-pings
Sync the Schedule
Nothing is monitored until the schedule has been synced. Run:
php artisan schedule-monitor:sync
Output similar to this confirms the setup (without Oh Dear configured, a yellow notice explains that the Oh Dear part was skipped):
Start syncing schedule...
Start syncing schedule with database...
Not syncing schedule with oh dear because not monitor_id is not set in the oh-dear config file.
Learn how to set this up at https://ohdear.app/docs/general/cron-job-monitoring/php#cron-monitoring-in-laravel-php.
All done! Now monitoring 4 scheduled tasks.
Run php artisan schedule-monitor:list to see which jobs are now monitored.
Add the Sync to Your Deployment
The schedule lives in your code, so it changes with every deployment. Add the sync to your deploy script, after the migrations:
php artisan migrate --force
php artisan schedule-monitor:sync
If a deployment adds a task and the sync is not run, the new task has no row in the database and its runs are silently ignored. If a deployment renames a task (for example by changing a command's arguments), the old row keeps showing as "late". The sync command page explains exactly what is created, updated, and deleted.
In local and staging environments, run the sync by hand when you change the schedule. Only tasks that run in the current environment (app.env) are synced.
Prune Old Log Items
Every run writes at least one log item, so the monitored_scheduled_task_log_items table grows without limit. The log item model uses Laravel's MassPrunable trait and deletes items older than delete_log_items_older_than_days (default 30). Schedule Laravel's model:prune command for it:
// routes/console.php
use Illuminate\Support\Facades\Schedule;
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem;
Schedule::command('model:prune', ['--model' => MonitoredScheduledTaskLogItem::class])
->daily()
->monitorName('prune-schedule-monitor-log-items');
The --model option is required: without it, model:prune only looks for prunable models in your application's own models directory. If you use a custom log item model, pass your class instead. The monitorName() call is optional but gives the prune task a readable name instead of the full command line.
Verify the Installation
php artisan schedule-monitor:list
Right after the first sync, every task appears under Monitored Tasks with -- for its start, finish, and failure times, and a next run date. Tasks listed under Unnamed Tasks or Duplicate Tasks need a name. After the scheduler has run a task, its timestamps fill in.
Troubleshooting Installation
| Symptom | Cause and fix |
|---|---|
InvalidClassException: The provided class name ... does not extend the required package class ... on every request or command |
A class configured under models does not extend the package model. See custom models. |
SQLSTATE[...]: ... no such table: monitored_scheduled_tasks |
The migration was not published or not run. |
| The sync says "Now monitoring 0 scheduled tasks" | The schedule is empty in this environment, all tasks are unnamed, or all use doNotMonitor(). Run schedule-monitor:list to see why. |
| Tasks run but nothing is logged | The sync has not run since the tasks were added or renamed. See Troubleshooting. |