What potential issues can arise when using fsockopen() function in PHP to check server status?

One potential issue that can arise when using the fsockopen() function in PHP to check server status is that it may result in a timeout if the server is not responding. To solve this issue, you can set a timeout value for the fsockopen() function to prevent it from waiting indefinitely for a response.

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

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

if (!$socket) {
    echo "Server is not responding.";
} else {
    echo "Server is up and running.";
    fclose($socket);
}