I am trying to properly handle fopen when the remote site or server is down..I "think" the script below is not handling it gracefully. It seems if the remote site is down, then the site that tries to run this script doesn't load as well...So what I am trying to do is prevent that somehow. How can I tell it to stop trying if the remote server takes too long?
if ($handle = @fopen('http://test.com/versions.xml','r')) {
$versions = fread($handle, 1024);
fclose($handle);
} elseif (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://test.com/versions.xml');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$versions = curl_exec($ch);
curl_close($ch);
}