How to Monitor PHP Cron Jobs with CronRabbit

PHP

The Problem

PHP CLI scripts invoked by cron can fatal error, run out of memory, or timeout. Without monitoring, these failures are invisible until data issues surface.

The Solution

Add a file_get_contents() or curl call to CronRabbit at the end of your script. Missing pings trigger instant alerts.

Why PHP Cron Jobs Fail Silently

PHP fatal errors, memory limit exhaustion (the default 128MB is often too low for batch scripts), and max_execution_time limits can kill your script mid-run.

Integration

Add a simple HTTP call at the end of your PHP script. Use file_get_contents() for zero dependencies, or cURL for robustness.

Code Examples

Basic monitoring with file_get_contents

PHP
<?php
$PING = "https://ping.cronrabbit.com/your-id";

file_get_contents("$PING/start");

try {
    processImports();
    file_get_contents($PING);
} catch (Exception $e) {
    file_get_contents("$PING/fail");
    throw $e;
}

Robust monitoring with cURL

PHP
<?php
function ping(string $url): void {
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_TIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FAILONERROR => true,
    ]);
    curl_exec($ch);
    curl_close($ch);
}

ping("https://ping.cronrabbit.com/your-id/start");
try {
    runBatchJob();
    ping("https://ping.cronrabbit.com/your-id");
} catch (Throwable $e) {
    ping("https://ping.cronrabbit.com/your-id/fail");
    throw $e;
}

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.