What are the potential uses of checking the availability of a host in PHP?

Checking the availability of a host in PHP can be useful for various reasons such as monitoring server status, testing network connectivity, or verifying if a website is online. This can help in troubleshooting potential issues and ensuring that services are running smoothly.

<?php
$host = 'example.com';
$port = 80;
$timeout = 3;

$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($fp) {
    echo 'Host is available';
    fclose($fp);
} else {
    echo 'Host is not available';
}
?>