Quick Start

This tutorial takes a Laravel application from no monitoring to a monitored schedule: you install the package, sync a small schedule, run it, and read the results in the console and in the database. Oh Dear notifications are set up separately in Oh Dear Setup.

1. Install the Package and Create the Tables

composer require spatie/laravel-schedule-monitor
php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations"
php artisan migrate

2. Define a Schedule

In Laravel 11 and later, the schedule usually lives in routes/console.php. Add a few tasks of different kinds:

// routes/console.php
use App\Jobs\SyncInventory;
use Illuminate\Support\Facades\Schedule;

// An Artisan command: named "inspire" automatically.
Schedule::command('inspire')->everyMinute();

// A queued job: named after its class, "App\Jobs\SyncInventory".
Schedule::job(new SyncInventory)->hourly();

// A closure: has no automatic name, so give it one.
Schedule::call(fn () => logger('heartbeat'))
    ->everyFiveMinutes()
    ->monitorName('heartbeat');

// A closure without a name: it cannot be monitored.
Schedule::call(fn () => logger('unnamed'))->daily();

The methods monitorName() and friends are added to every scheduled event by the package. If your application still defines its schedule in app/Console/Kernel.php, the same methods work on $schedule->command(...) and the other builders there.

3. Sync the Schedule

php artisan schedule-monitor:sync

Expected output, similar to:

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 3 scheduled tasks.
Run php artisan schedule-monitor:list to see which jobs are now monitored.

Three tasks are monitored: the unnamed closure was left out. The yellow Oh Dear notice is expected until you configure Oh Dear.

4. Look at the List

php artisan schedule-monitor:list

The output looks similar to this (dates depend on the current time):

 Monitored Tasks
 inspire (command) ................................ Every minute
   ⇁ Started at: --   ⇁ Finished at: --   ⇁ Failed at: --
   ⇁ Next run: 2026-12-03 10:15:00   ⇁ Grace time: 5 minutes
 App\Jobs\SyncInventory (job) ...................... Every hour
   ⇁ Started at: --   ⇁ Finished at: --   ⇁ Failed at: --
   ⇁ Next run: 2026-12-03 11:00:00   ⇁ Grace time: 5 minutes
 heartbeat (closure) ......................... Every 5 minutes
   ⇁ Started at: --   ⇁ Finished at: --   ⇁ Failed at: --
   ⇁ Next run: 2026-12-03 10:15:00   ⇁ Grace time: 5 minutes

 Unnamed Tasks
 These tasks cannot be monitored because no name could be determined for them.
 closure ................................................ Every day
 To monitor these tasks you should add ->monitorName() in the schedule to manually specify a name.

5. Run the Scheduler

In production, cron calls php artisan schedule:run every minute. Locally you can run it once by hand:

php artisan schedule:run

Every task that is due runs, and for each monitored task the package records a starting log item and then a finished (or failed) log item. Run the list again and the Started at and Finished at columns of the tasks that ran are filled in.

Tip: php artisan schedule:work keeps running the scheduler every minute in the foreground, which is handy for watching the list change during development.

6. Inspect the Log Items

The history is in monitored_scheduled_task_log_items. Using Tinker:

php artisan tinker
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTask;

$task = MonitoredScheduledTask::findByName('inspire');

$task->logItems()->first()->only(['type', 'meta', 'created_at']);
// [
//   "type" => "finished",
//   "meta" => ["runtime" => 0.21, "exit_code" => 0, "memory" => 25165824, "output" => null],
//   "created_at" => ...,
// ]

logItems() is ordered newest first. The output is null unless the task uses storeOutputInDb(). The meaning of each meta key is described in How Monitoring Works.

7. See a Failure

Make a command fail and watch it show up. For example, schedule a command that returns a non-zero exit code:

// routes/console.php
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;

Artisan::command('demo:fail', fn () => 1); // exit code 1

Schedule::command('demo:fail')->everyMinute();

Sync again (the schedule changed), run the scheduler, and list:

php artisan schedule-monitor:sync
php artisan schedule:run
php artisan schedule-monitor:list

The Failed at time of demo:fail is now shown in red, because the last failure happened after the last start. The log item has type failed with the exit code in its meta.

8. Prepare for Production

  • Add php artisan schedule-monitor:sync to your deployment script (details).
  • Schedule model:prune for the log items (details).
  • Set a realistic grace time for long-running tasks.
  • Set up Oh Dear if you want notifications.

See Also