Monitor cronjobs inside Wordpress

Learn how to monitor and track WordPress cronjob executions using Operational.co to ensure scheduled tasks run reliably and catch failures.

What is cronjob monitoring in WordPress

WordPress uses cron-like tasks to schedule repeated actions.
These cronjobs perform tasks like publishing scheduled posts, cleaning up items, or sending emails.

Monitoring these jobs helps you catch failures, track performance, and ensure your site runs smoothly.
For example, if a backup cronjob fails, you need an alert to fix it before losing data.

Tracking cronjobs with Operational

Operational is an open-source toolkit for capturing and tracking events in any tech product.
You can use Operational to log cronjob executions in your WordPress site.
It provides a simple API to send event data to your Operational dashboard.

Operational Usage

Setting up Operational

  1. Go to https://app.operational.co and create an account.
  2. Verify your email and log in to the dashboard.
  3. Create a new project for your WordPress site.
  4. Copy the API key provided in the project settings.

Tracking WordPress cronjob events

<?php
// Send a successful cronjob execution event to Operational
// Add this inside add_action( 'bl_cron_hook', 'bl_cron_exec' ); hook
$payload = [
    'name' => 'Cronjob Executed',
    'avatar' => '',
    'content' => 'Daily backup cronjob ran successfully on example.com at 03:00 AM'
];

$ch = curl_init('https://api.operational.co/events/ingest');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);
<?php
// Send a failed cronjob execution event to Operational
$payload = [
    'name' => 'Cronjob Failed',
    'avatar' => '',
    'content' => 'Hourly cleanup cronjob failed on example.com at 02:15 AM'
];

// The same cURL setup as above, using your API key and endpoint

These examples show how to report both successful and failed cronjobs to your Operational dashboard.

Conclusion

Using Operational to monitor WordPress cronjobs saves time and helps you catch issues early.

You can view real-time events and trends in one place. You can also make it send push notifications to your device.

Learn more at https://operational.co or try snippets in our Playground: https://operational.co/playground