What potential issues could arise when using the fsockopen() function to check the reachability of a website in PHP?

One potential issue that could arise when using the fsockopen() function to check the reachability of a website in PHP is that it may not handle errors or timeouts effectively, leading to slow performance or inaccurate results. To solve this issue, you can set a timeout value for the fsockopen() function to prevent it from waiting indefinitely for a response.

$host = 'www.example.com';
$port = 80;
$timeout = 5; // Set timeout value to 5 seconds

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

if (!$socket) {
    echo "Unable to connect to $host: $errstr ($errno)";
} else {
    echo "Successfully connected to $host";
    fclose($socket);
}