Cron Job Monitoring for PHP applications

Cron job monitoring in your PHP code

Oh Dear users can add cron job monitoring to any existing PHP script. When you create a cronjob monitor in your account, you're given a unique pingback URL that should be called every time a script completes.

In this guide, we'll cover how you can implement that in your existing PHP code.

Cron monitoring in generic PHP

This is a technique that can be used in any PHP application, regardless of the framework you use.

At the very bottom of your scheduled command, add a call to the file_get_contents() function that will call back to us and inform you the job has ended.


Note: make sure your script stops executing on error conditions, so the file_get_contents() function isn't called even if the script has failed.

Cron monitoring in Laravel (PHP)

Note: there's a convenient Laravel package called spatie/laravel-schedule-monitor you can use that syncs up nicely with Oh Dear. Please refer to this package's documentation on how it works.

In standard Laravel, you can use the thenPing() method in your Console scheduler. You'll find this in the app/Console/Kernel.php file.

class Kernel extends ConsoleKernel
    protected function schedule(Schedule $schedule)

Cron monitoring in Symfony (PHP)

This example uses the zenstruck/schedule-bundle scheduler in Symfony.

You can either define it in your PHP code:

use Zenstruck\ScheduleBundle\Schedule\Task\PingTask;

/* @var  \Zenstruck\ScheduleBundle\Schedule $schedule */

$schedule->add(new PingTask(''));

Or in your configurations:

# config/packages/zenstruck_schedule.yaml
    # note the "ping:" prefix
    - task: ping:
      frequency: '0 * * * *'

Was this page helpful to you? Feel free to reach out via or on Twitter via @OhDearApp if you have any other questions. We'd love to help!