What are the potential pitfalls of using fsockopen in PHP for server status checks?

Potential pitfalls of using fsockopen in PHP for server status checks include potential timeouts, connection errors, and performance issues. To mitigate these risks, it is important to set appropriate timeout values, handle connection errors gracefully, and consider the impact on server performance when making frequent status checks.

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

$socket = @fsockopen($host, $port, $errno, $errstr, $timeout);

if (!$socket) {
    echo "Error connecting to server: $errstr ($errno)";
} else {
    echo "Server is reachable";
    fclose($socket);
}