What are some common methods for monitoring website uptime using PHP?

Monitoring website uptime is crucial for ensuring that your website is always available to users. One common method for monitoring website uptime using PHP is to create a script that periodically sends a request to the website and checks for a successful response. This can be done using PHP's cURL library to make HTTP requests and check the response code.

<?php
function checkWebsiteUptime($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
    
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode == 200) {
        echo "Website is up and running!";
    } else {
        echo "Website is down!";
    }
}

$url = "http://www.example.com";
checkWebsiteUptime($url);
?>