What are the potential pitfalls of simply pinging the host of a server to check for online status?

Pinging the host of a server to check for online status may not always provide accurate information as the host may be reachable but the server itself may be down. To ensure accurate status checks, it is better to establish a connection to the server and check for a successful response. This method provides a more reliable indication of the server's online status.

$host = 'example.com';
$port = 80;
$timeout = 1;

$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($fp) {
    echo 'Server is online';
    fclose($fp);
} else {
    echo 'Server is offline';
}