Oohh… I shouldn’t do coding late at night anymore… #-o
So, in the light of day, a couple more things were added to address the issues…
First, the URL for the test page I was not the one I was working on (but is now)
http://saratoga-weather.org/advforecast2-testpage.php should work as a demo.
Second, I did a bit more (belt and suspenders) check on the page from the cache, and fetch the backup if the cache page is bogus.
That’s done by replacing
if (filemtime($cacheName) + 1800 > time()) {
$html = implode('', file($cacheName));
} else {
$html = fetchUrlWithoutHanging($fileName,$cacheName);
if (preg_match('/Temporary|Location:|defaulting to/Uis',$html)) {
$usingFile = "(Zone forecast)";
$html = fetchUrlWithoutHanging($backupfileName,$cacheName);
}
$fp = fopen($cacheName, "w");
$write = fputs($fp, $html);
fclose($fp); }
with
if (filemtime($cacheName) + 1800 > time()) {
$html = implode('', file($cacheName));
if (preg_match('/Temporary|Location:|defaulting to/is',$html)) {
$usingFile = "(Zone forecast)";
$html = fetchUrlWithoutHanging($backupfileName,$cacheName);
}
} else {
$html = fetchUrlWithoutHanging($fileName,$cacheName);
if (preg_match('/Temporary|Location:|defaulting to/Uis',$html)) {
$usingFile = "(Zone forecast)";
$html = fetchUrlWithoutHanging($backupfileName,$cacheName);
}
$fp = fopen($cacheName, "w");
$write = fputs($fp, $html);
fclose($fp); }
Third, the Notice: errors were due to fewer days being returned to the Zone forecast than the regular forecast (while error_reporting is set to E_ALL). That can be fixed by changing:
for ($i=0;$i<=13;$i++) {
print "<tr valign =\"top\" align=\"left\">\n";
to the more sensible
for ($i=0;$i<count($forecasttitles);$i++) {
print "<tr valign =\"top\" align=\"left\">\n";
(or using ‘error_reporting(E_ALL ^ E_NOTICE);’ )
Best regards,
Ken