Hi Wim,
It uses preg_match('!"updated":\s+"([^"]+)"!is', $html, $matches);
if (isset($matches[1])) {
$age = time() - strtotime($matches[1]);
if ($age > 12 * 60 * 60) {
$agehms = sec2hmsADV($age);
$Status.= "<!-- point forecast more than 12hrs old (age h:m:s is $agehms) .. use Zone forecast instead -->\n";
$Force = 2;
$usingFile = "(Zone forecast)";
$html = fetchUrlWithoutHanging($backupfileName, $cacheName);
$lastURL = $backupfileName; // remember if error encountered
$fSize = strlen($html);
$Status.= "<!-- loaded $usingFile $backupfileName - $fSize bytes -->\n";
to check the 'age' of the forecast v.s. the internal "updated": info in the JSON.
From SoMDWx example, the cache file was loaded, so I can't tell if the 301 was previously followed by code if ($Force == 1 or !file_exists($cacheName) or (file_exists($cacheName) and filemtime($cacheName) + $refreshTime < time())) {
$html = fetchUrlWithoutHanging($fileName, $cacheName);
preg_match('/HTTP\/1.1 (\d+)/', $html, $m);
if (isset($m[1]) and $m[1] >= '400') {
$Force = 2;
$Status.= "<!-- Oops.. point forecast unavailable RC=" . $m[1] . " - using Zone instead -->\n";
}
else {
$lastURL = $fileName; // remember if error encountered
$fSize = strlen($html);
$Status.= "<!-- loaded $fileName - $fSize bytes -->\n";
if (preg_match('/Location: (.*)\r\n/Uis', $html, $matches)) {
$newLoc = $matches[1];
$newurl = APIURL . $newLoc;
$usingFile = "(retry forecast)";
$html = fetchUrlWithoutHanging($newurl, $cacheName);
$fSize = strlen($html);
$Status.= "<!-- loaded $usingFile $newurl - $fSize bytes -->\n";
}
...