Manage your sites with the PHP SDK
This page will get you started managing your sites 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 sites #
The simplest example is one where we list all your sites on your Oh Dear accounts.
$sites = $ohDear->sites();
This will return an array of
You can get a few properties of a site.
$site->id; $site->url; ...
You can also get a single site:
Add a site through the SDK #
A new site can be created with
$ohDear->createSite([ 'url' => 'https://yourbrandnewsite.tld', 'team_id' => $yourTeamId ]);
Take a look at the User section to learn how to get your team id.
https site is created, all checks will automatically be enabled. When an
http site is created only the uptime and broken links checks will be enabled.
If you only want to enable specific checks when creating a site you can just pass them like this:
$ohDear->createSite([ 'url' => 'https://yourbrandnewsite.tld', 'team_id' => $yourTeamId 'checks' => ['uptime', 'mixed_content'] ]);
Valid values to pass to checks are
Deleting a site #
A site can easily be deleted. This assumes the
$site is an instance of
OhDear\PhpSdk\Resources\Site, which you can get with the
$site->delete(); // This particular site is deleted
See the retrieving all sites section above to get all available sites.
Managing maintenance periods #
You can use the SDK to put a site in maintenance mode. This means that Oh Dear will continue to monitor your site, but will not send any notification while the site is in maintenance mode.
A maintenance period will stop after an hour by default. To shorten or extend that period, you can pass an amount of seconds.
To manually stop maintenance mode, use this code:
When integrated into your deployment or maintenance mechanisme, this will allow you to create and stop a maintenance period for just the right amount of time.