surrounding the output of the script .. change styling to suit. $boxStyle = 'style="border: dashed 1px black; background-color:#FFFFCC; margin: 5px; padding: 0 5px;"'; // $cacheFileDir = './cache/'; // default cache file directory $refetchSeconds = 60; // refetch every nnnn seconds $cacheName = 'radar-status-'.$statRadar.'.txt'; // used to store the file so we don't have to // fetch it each time $showHMSAge = true; // =false for number of seconds, =true for H:M:S age display // end of settings // Constants // don't change $fileName or script may break ;-) $fileName = 'https://radar3pub.ncep.noaa.gov/'; // end of constants // --------------------------------------------------------- // overrides from Settings.php if available global $SITE; #if (isset($SITE['GR3radar'])) {$statRadar = $SITE['GR3radar'];} // Useful only in 'radar-status.php'!!! if (isset($SITE['tz'])) {$ourTZ = $SITE['tz'];} if (isset($SITE['timeFormat'])) {$timeFormat = $SITE['timeFormat'];} #if (isset($SITE['showradarstatus'])) {$noMsgIfActive = ! $SITE['showradarstatus'];} // Default isn't helpful here! if (isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } // end of overrides from Settings.php if available // ------ start of code ------- if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) { //--self downloader -- $filenameReal = __FILE__; $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } // Check parameters and force defaults/ranges if ( ! isset($_REQUEST['inc']) ) { $_REQUEST['inc']=""; } if (!isset($doIncludeRS) ) { $doIncludeRS = true; } if (isset($doIncludeRS) and $doIncludeRS ) { $includeMode = "Y"; } else { $includeMode = $_REQUEST['inc']; // any nonblank is ok } if ($includeMode) {$includeMode = "Y";} if (isset($_REQUEST['show']) ) { // for testing $noMsgIfActive = (strtolower($_REQUEST['show']) != 'active'); } if (isset($_REQUEST['nexrad']) ) { // for testing $statRadar = substr(strtoupper($_REQUEST['nexrad']),0,4); } if (isset($_REQUEST['cache'])) {$refetchSeconds = 1; } $statRadar = strtoupper($statRadar); // omit HTML ... if only tables wanted // --------------- customize HTML if you like ----------------------- if (! $includeMode) { ?> Radar Status for <?php print $statRadar ?> NEXRAD station \n"; // refresh cached copy of page if needed // fetch/cache code by Tom at carterlake.org $cacheName = $cacheFileDir . $cacheName; $Debug = ''; if (file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds > time()) { print "\n"; $html = implode('', file($cacheName)); } else { print "\n"; $html = RS_fetchUrlWithoutHanging($fileName.'rcvxmit.sites.public.html',false); print $Debug; $Debug = ''; list($hdr1,$content1) = explode("\r\n\r\n",$html); print "\n"; $html2 = RS_fetchUrlWithoutHanging($fileName.'ftm.txt',false); print $Debug; $Debug = ''; list($hdr2,$content2) = explode("\r\n\r\n",$html2); if(strlen($content1) > 100 and strlen($content2) > 100) { $fp = fopen($cacheName, "w"); if ($fp) { $write = fputs($fp, $html); $write = fputs($fp,"\n||||||\n"); $write = fputs($fp,$hdr2."\n
\n".$content2."
\n"); fclose($fp); print "\n"; } else { print "\n"; } $html .= "\n||||||\n"."\n
\n".$content2."
\n"; } else { print "\n"; print "\n"; print "\n"; print "\n"; } } # Set timezone in PHP5/PHP4 manner if (!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); # $Status .= "\n"; } else { date_default_timezone_set("$ourTZ"); # $Status .= "\n"; } if(strlen($html) < 250) { print "\n"; return; } // extract the updated date/time // print "
\n";
  preg_match_all('|Last-Modified: (.*)\r|Uis',$html,$matches);
//  print_r($matches);
  if(!isset($matches[1][0])) { // no Last-Modified header.. look for the status line
    // Status as of 08.03.2016 wed 21:05:01 utc
    preg_match_all('|Status as of (\S+)\s+\S+\s(\S+) utc|Uis',$html,$matches);
	$t = explode('.',$matches[1][0]);

	$UDate = $t[2].'-'.$t[0].'-'.$t[1] . ' ' . $matches[2][0] . ' GMT';
	//print "\n";
	$UDate = gmdate('r',strtotime($UDate));
  } else {
  $UDate = $matches[1][0];
  }
 // $UDate = 'Fri, 05 Jun 2015 00:14:01 GMT'
  $UDp = explode(" ",$UDate);
  //print "\n";
 /*
 Array $UDp is now:
(
    [0] => Tue,
    [1] => 08
    [2] => Mar
    [3] => 2016
    [4] => 21:40:01
    [5] => +0000
)
*/
  $UTCdate = strtotime($UDate);
  $LCLdate = date($timeFormat,$UTCdate);
  //print "\n";
  
/*  The data looks like this:

KMUX
23:28:17 KMVX
00:15:17 then looked like KAMX
04:06:04 KAPX
04:26:04 KARX
04:42:27 KATX
02:33:21 now looks like KVNX
19:03:46
07/06/15 KVTX
20:49:11
07/06/15 */ preg_match_all('|]*>(.*)|Uis',$html,$matches); // print "\n"; $status = $matches[1]; $recs = $matches[3]; /* [104] => KMUX
20:50:16
07/06/15 [105] => KMVX
20:46:59
07/06/15 */ print "\n"; foreach ($recs as $n => $rec) { if (! preg_match("|$statRadar|",$rec)) {continue;} $statColor = $status[$n]; $statColor = str_replace('#0000FF','#FF0000',$statColor); // print "statColor='$statColor'\n"; preg_match_all('|(.*)
(.*)
(.*)|is',$rec,$matches); // print "\n"; $statRadar = $matches[1][0]; $lastUTCtime = $matches[2][0]; $td = explode('/',$matches[3][0]); // print "\n"; $lastUTCdate = '20'.$td[2].'-'.$td[0].'-'.$td[1].' '.$lastUTCtime.' GMT'; // print "\n"; $t=strtotime($lastUTCdate); print "\n"; $age = $UTCdate - $t; // if ($age < 0) { $age += (60*60*24); } // account for one day extra downtime if need be $ageHMS = gmdate('H:m:s',$age); preg_match_all('||is',$rec,$matches); $curStatus = 'Active'; if ($statColor <> '#33FF33') { $curStatus = 'Data not recent'; } if (isset($matches[1][0])) { $curStatus = $matches[1][0]; } // print "statRadar='$statRadar' lastUTCtime='$lastUTCtime' curStatus='$curStatus'\n"; // print "$prec"; // print "$rec"; break; // print "$rec"; // this shouldn't print ever } // extract the messages preg_match('|]*>(.*)
|Usi',$html,$matches); $messages = $matches[1]; // now split up the messages and process $messages = preg_replace('|NOUS|Us','||NOUS',$messages) . '|'; // add message delimiters $messages = preg_replace('|ÿÿ|Uis',"\n||NOUSnn",$messages); // remove garbage characters. $messages = preg_replace('|ð|Uis','',$messages); // remove garbage characters preg_match_all('!\|NOUS(.*)\|!Us',$messages,$matches); // split the messages $messages = $matches[1]; // now have array of messages in order $radarMsgs = array(); // for storing the messages in a 'cleansed' format by Radar key, then date foreach ($messages as $n => $msg) { /* a $msg looks like this: 66 KMTR 200618 FTMMUX MESSAGE DATE: JAN 20 2008 06:17:55 KMUX SAN FRANCISCO RADAR IS EXPERIENCING INTERMITTENT DATA FLOW INTERUPTIONS. TROUBLE-SHOOTING PROCEDURES ARE CURRENTLY UNDERWAY TO DETERMINE THE PROBLEM AND RESTORE NORMAL OPERATIONS. */ $msgline = explode("\n",$msg); // get 'em separated into individual lines. $t = explode(' ',trim($msgline[0])); $thisRadar = $t[1]; $thisTD = $t[2]; if (substr($thisRadar,1,3) != substr($msgline[1],3,3)) { // sometimes one reports for another $thisRadar = substr($thisRadar,0,1) . substr($msgline[1],3,3); } preg_match('|date:\s+(.*)|i',trim($msgline[2]),$matches); $istart = 3; if (!isset($matches[1])) { // oops.. no message line $istart--; /* use the Updated UTC to 'fill in the blanks' from the header line ( [0] => Mon [1] => Jan [2] => 21 [3] => 00:14:59 [4] => CUT [5] => 2008 ) */ $tdate = substr($thisTD,0,2) . '-' . $UDp[1] . '-' . $UDp[5] . ' ' . substr($thisTD,2,2) . ':' . substr($thisTD,4,2) . ':00 UTC'; $thisDate = strtotime($tdate); } else { $thisDate = strtotime($matches[1] . ' UTC'); } $thisMsg = ''; for ($i=$istart;$i Array ( [1200854014] => THE KVNX WSR-88D WILL BE DOWN FOR A BRIEF PERIOD BETWEEN 1840 AND 1900 UTC FOR R EQUIRED MAINTENANCE. AT WFO/OUN, 1833 UTC - 1/20/08 [1200857882] => THE KVNX WSR-88D HAS BEEN RETURNED TO SERVICE. AT WFO/OUN, 1935 UTC - 1/20/08 ) [KMUX] => Array ( [1200809875] => KMUX SAN FRANCISCO RADAR IS EXPERIENCING INTERMITTENT DATA FLOW INTERUPTIONS. TROUBLE-SHOOTING PROCEDURES ARE CURRENTLY UNDERWAY TO DETERMINE THE PROBLEM AND RESTORE NORMAL OPERATIONS. [1200890280] => KMUX SAN FRANCISCO RADAR IS CONTINUING TO EXPERIENCE INTERMITTENT DATA FLOW INTERUPTIONS. TROUBLE-SHOOTING PROCEDURES CONTINUE. PROBLEMS ARE LIKELY WITH TELCO CONNECTIONS AND VERIZON TECHNICIANS WILL RESUME WITH THEIR PROCESSES ON MONDAY. ) */ // Output the status if (isset($statColor) and (!$noMsgIfActive or $statColor != '#33FF33') ) { print "
\n"; $pAge = ($showHMSAge)?sec2hmsRS($age)." (Hours:Minutes:Seconds)":"$age secs"; print "

NEXRAD Radar $statRadar status: $curStatus [last data $pAge ago] as of $LCLdate

\n"; if (isset($radarMsgs[$statRadar])) { foreach ($radarMsgs[$statRadar] as $timestamp => $msg) { $msg = htmlspecialchars($msg); $msg = preg_replace('|\n|is',"
\n",$msg); print "

Message date: " . date($timeFormat,$timestamp) . "
\n"; print $msg . "

\n"; } } $niceFileName = preg_replace('!&!is','&',$fileName); print "

NWS WSR-88D Transmit/Receive Status

\n"; print "
\n"; } // end suppress if radar active and $noMsgIfActive == true elseif (isset($statColor) ){ print "\n"; if (isset($radarMsgs[$statRadar])) { foreach ($radarMsgs[$statRadar] as $timestamp => $msg) { $msg = htmlspecialchars($msg); print "\n"; } } } else { print "

NEXRAD radar $statRadar status not found.

\n"; } print ""; // print footer of page if needed // --------------- customize HTML if you like ----------------------- if (! $includeMode ) { ?> \n"; $ch = curl_init(); // initialize a cURL session curl_setopt($ch, CURLOPT_URL, $theURL); // connect to provided URL curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // don't verify peer certificate curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (radar-status-getradar.php - saratoga-weather.org)'); curl_setopt($ch,CURLOPT_HTTPHEADER, // request LD-JSON format array ( "Accept: text/html,text/plain" )); 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 // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow Location: redirect // curl_setopt($ch, CURLOPT_MAXREDIRS, 1); // but only one time 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 $Debug .= "\n"; } $data = curl_exec($ch); // execute session if(curl_error($ch) <> '') { // IF there is an error $Debug .= "\n"; // display error notice } $cinfo = curl_getinfo($ch); // get info on curl exec. /* curl info sample Array ( [url] => https://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 ) */ $Debug .= "\n"; //$Debug .= "\n"; curl_close($ch); // close the cURL session //$Debug .= "\n"; $i = strpos($data,"\r\n\r\n"); $headers = substr($data,0,$i); $content = substr($data,$i+4); if($cinfo['http_code'] <> '200') { $Debug .= "\n"; } return $data; // return headers+contents } else { // print "\n"; $STRopts = array( 'http'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (radar-status-getradar.php - saratoga-weather.org)\r\n" . "Accept: text/html,text/plain\r\n" ), 'https'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (radar-status-getradar.php - saratoga-weather.org)\r\n" . "Accept: text/html,text/plain\r\n" ) ); $STRcontext = stream_context_create($STRopts); $T_start = RS_fetch_microtime(); $xml = file_get_contents($url,false,$STRcontext); $T_close = RS_fetch_microtime(); $headerarray = get_headers($url,0); $theaders = join("\r\n",$headerarray); $xml = $theaders . "\r\n\r\n" . $xml; $ms_total = sprintf("%01.3f",round($T_close - $T_start,3)); $Debug .= "\n"; $Debug .= "<-- get_headers returns\n".$theaders."\n -->\n"; // print " file() stats: total=$ms_total secs.\n"; $overall_end = time(); $overall_elapsed = $overall_end - $overall_start; $Debug .= "\n"; // print "fetch function elapsed= $overall_elapsed secs.\n"; return($xml); } } // end ECF_fetch_URL // ------------------------------------------------------------------ function RS_fetch_microtime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } //------------------------------------------------------------------------------------------ // function sec2hmsRS ($sec, $padHours = false) { // holds formatted string $hms = ""; if (! is_numeric($sec)) { return($sec); } // there are 3600 seconds in an hour, so if we // divide total seconds by 3600 and throw away // the remainder, we've got the number of hours $hours = intval(intval($sec) / 3600); // add to $hms, with a leading 0 if asked for $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':' : $hours. ':'; // dividing the total seconds by 60 will give us // the number of minutes, but we're interested in // minutes past the hour: to get that, we need to // divide by 60 again and keep the remainder $minutes = intval(($sec / 60) % 60); // then add to $hms (with a leading 0 if needed) $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':'; // seconds are simple - just divide the total // seconds by 60 and keep the remainder $seconds = intval($sec % 60); // add to $hms, again with a leading 0 if needed $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); // done! return $hms; } // --------------end of functions --------------------------------------- ?>