Clickable NWS National Advisory Maps
';?>
';
}
############################################################################
# End of Page
############################################################################
// replacement for some of the "fetch data without hanging" routines in the code
// get contents from one URL and return as string starting with data portion
// returns array($headers, $content)
function getRemoteDataWithoutHanging($url, $cacheName, $ldJson, $geoJson, $redirects) {
global $needCookie, $SITE;
$overall_start = time();
if (empty($url) )
{
echo "\n";
$content = "";
$headers = "";
}
else
{
$overall_start = time();
// Set maximum number of seconds to wait for feed before displaying page without feed
$numberOfSeconds=6;
// Thanks to Curly from ricksturf.com for the cURL fetch functions
$curlVersion = curl_version();
// echo "\n";
if (!$curlVersion['features'] & CURL_VERSION_SSL)
echo "\n";
$data = '';
$domain = parse_url($url,PHP_URL_HOST);
// add cache-buster to URL if needed
$theURL = str_replace('nocache','?'.$overall_start,$url);
echo "\n";
$ch = curl_init(); // initialize a cURL session
curl_setopt($ch, CURLOPT_URL, $theURL); // connect to provided URL
// we will verify peer certificate...
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT,'AlertsFetch/1.1 (Web Application, www.gwwilkins.org)');
if ($ldJson)
{
curl_setopt($ch,CURLOPT_HTTPHEADER, // request LD-JSON format
array (
"Accept: application/ld+json"
));
}
else if ($ldJson)
{
curl_setopt($ch,CURLOPT_HTTPHEADER, // request GEO-JSON format
array (
"Accept: application/geo+json"
));
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $numberOfSeconds); // connection timeout
curl_setopt($ch, CURLOPT_TIMEOUT, $numberOfSeconds); // data timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the data transfer
curl_setopt($ch, CURLOPT_NOBODY, false); // set nobody
curl_setopt($ch, CURLOPT_HEADER, true); // include header information
if (isset($redirects) && ($redirects > 0) )
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow Location: redirect
curl_setopt($ch, CURLOPT_MAXREDIRS, $redirects); // however many times requested
}
if (isset($needCookie[$domain]))
{
curl_setopt($ch, $needCookie[$domain]); // set the cookie for this request
curl_setopt($ch, CURLOPT_COOKIESESSION, true); // and ignore prior cookies
echo "\n";
}
$data = curl_exec($ch); // execute session
if(curl_error($ch) <> '') // IF there is an error
{
echo "\n"; // display error notice
}
$cinfo = curl_getinfo($ch); // get info on curl exec.
/*
curl info sample
Array
(
[url] => http://saratoga-weather.net/clientraw.txt
[content_type] => text/plain
[http_code] => 200
[header_size] => 266
[request_size] => 141
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.125
[namelookup_time] => 0.016
[connect_time] => 0.063
[pretransfer_time] => 0.063
[size_upload] => 0
[size_download] => 758
[speed_download] => 6064
[speed_upload] => 0
[download_content_length] => 758
[upload_content_length] => -1
[starttransfer_time] => 0.125
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 74.208.149.102
[certinfo] => Array
(
)
[primary_port] => 80
[local_ip] => 192.168.1.104
[local_port] => 54156
)
*/
echo "\n";
//echo "\n";
curl_close($ch); // close the cURL session
//echo "\n";
$i = strpos($data,"\r\n\r\n");
$headers = substr($data,0,$i);
$content = substr($data,$i+4);
if($cinfo['http_code'] <> '200')
{
echo "\n";
$content = ""; // didn't get good data
}
} // if URL passed in
if (empty($content) )
{
// see if we have cached data we can return
$headers = "";
echo "\n";
if (!empty($cacheName) )
{
echo "\n";
if ( ! file_exists($cacheName) )
{
echo "\n";
$content = "";
}
else
{
echo "\n";
$content = file_get_contents($cacheName);
}
} // end if cache file name given
} // end if no content
else if (!empty($cacheName) )
{
// write cache file if requested
echo "\n";
$fp = fopen($cacheName, "w");
echo "\n";
$bytes = fwrite ($fp, $content);
echo "\n";
fclose($fp);
}
$remoteData = array($headers, $content);
return $remoteData;
} // end getRemoteDataWithoutHanging
?>