Manage your cron monitoring with the PHP SDK
This page will get you started managing your cron job monitors with the PHP SDK. Make sure you've read the getting started guide first. Once that's done, you should have our package & authentication ready to go.
Retrieve all cron job monitors per site
Cron job monitors are attached to a site. In order to get a list of defined monitors, you'll need a site ID.
In this example, let's use site ID
1 and retrieve all cron job monitors for it.
$cronChecks = $ohDear->cronChecks(1);
This will return an array of
You can get a few properties of a cron job monitor:
$check->id; $check->name; $check->uuid; $check->type; $check->checkId; $check->frequencyInMinutes; $check->pingUrl; $check->graceTimeInMinutes; $check->cronExpression; $check->description; ...
Add a cron job monitor through the SDK
You can create a new cron job monitor using one of two methods:
createSimpleCronCheck(): lets you define a frequency and a grace time
createCronCheck(): lets you provide a
crontab-style syntax for defining the frequency
For example, to use the simple cron monitor definition:
$check = $ohDear->createSimpleCronCheck( 1, // Site ID 'your-cron-name', // Name 5, // Frequency (minutes) 10, // Grace time (minutes) 'your description', // A description of this cron monitor );
Or the crontab-style one:
$check = $ohDear->createSimpleCronCheck( 1, // Site ID 'your-cron-name', // Name '* * * * *', // Crontab expression 10, // Grace time 'your description', // A description 'UTC', // Your server timezone );
The return value is an instance of
OhDear\PhpSdk\Resources\CronCheck, with all the properties available as defined above.
Deleting a cron job monitor
A cron job monitor can easily be deleted. If you have the cron object, you can call the
delete() method on it:
$cronCheck->delete(); // This particular cron job monitor is deleted
Alternatively, you can use the SDK to delete a particular ID:
$ohdear->deleteCronCheck(1); // This will delete cron job ID 1
Syncing a large list of cron job monitors
There's a special function available called
syncCronChecks() that allows you to bulk-update a list of cron job monitors for a site.
$ohdear->syncCronChecks(1, [ $cronCheck1, $cronCheck2, $cronCheck3, ]);
Please note: this will delete all cron jobs that are not present in the new