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 OhDear\PhpSdk\Resources\Site instances.

You can get a few properties of a site.

$site->id;
$site->url;
...

You can also get a single site:

$ohDear->site($siteId);

Add a site through the SDK #

A new site can be created with createSite().

$ohDear->createSite([
   'url' => 'https://yourbrandnewsite.tld',
   'team_id' => $yourTeamId
]);

Take a look at the User section to learn how to get your team id.

When an 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 uptime, broken_links, certificate_health, mixed_content and certificate_transparency.

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 sites() method.

$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.

$ohDear->site($siteId)->startMaintenance();

A maintenance period will stop after an hour by default. To shorten or extend that period, you can pass an amount of seconds.

$ohDear->site($siteId)->startMaintenance($durationOfMaintenancePeriodInSeconds);

To manually stop maintenance mode, use this code:

$ohDear->site($siteId)->stopMaintenance();

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.

Was this page helpful to you? Feel free to reach out via support@ohdear.app or on Twitter via @OhDearApp if you have any other questions. We'd love to help!