What best practices should be followed when implementing a website uptime monitoring system using PHP and cron jobs?

When implementing a website uptime monitoring system using PHP and cron jobs, it is important to follow best practices to ensure accurate and reliable monitoring. This includes setting up regular checks at frequent intervals, handling errors gracefully, and sending alerts when downtime is detected.

<?php

// PHP script to check website uptime
$url = 'http://www.example.com';
$response = get_headers($url);
if ($response && strpos($response[0], '200')) {
    // Website is up, do nothing
} else {
    // Website is down, send alert
    mail('admin@example.com', 'Website Down', 'The website is currently down.');
}

?>