Categories
Web

PHP Cron Push Monitoring

I run a cron job every 5 minutes to execute background processes. Once they have successfully completed, I execute the following PHP function to verify their success and measure the execution time. If the execution fails, it sends me a push notification indicating that the push/heartbeat was not received within the expected timeframe. I monitor the push timeframes on statuscake.com.

Configuration for my 5-minute (300-second) check.

PHP

Execution and monitoring of execution time using StatusCake Push (Heartbeat).

If you’d like to use the code and function, don’t forget to update the PK and TestID with your values.

function sendStatusCakeGETRequest() {
    // URL and parameters
    $url = 'https://push.statuscake.com/?PK=abc123&TestID=123456789&time=' . round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"])*1000,0);

    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute the cURL session
    $response = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        echo 'cURL error: ' . curl_error($ch);
    }

    // Close cURL session
    curl_close($ch);

    // Output the response
    echo 'Response from StatusCake: ' . $response;
}

sendStatusCakeGETRequest();
  • https://www.statuscake.com/kb/knowledge-base/what-is-push-monitoring/

The `time` parameter is optional, and defaults to 0. The value is interpreted in milliseconds. (1000ms = 1 second)

https://www.statuscake.com/kb/knowledge-base/what-is-push-monitoring/

These are the results with everything set up.