Once in a blue moon, I'll run into a situation where my MBtags.php file is incomplete. Here is one example, where the file ended right here:
rain0total-val30|44.51|// rain value 30 minutes ago:|:
rain0total-val60|44.51|// rain value 60 minutes ago:|:
rain0total-hmin|44.51|// rain min of this hour:|:
rain0total-hmintime|20150612111939|// rain timestamp min of this hour:|:
rain0total-h
I'd like to figure out why this happens but first I want to be able to detect the problem on the server and continue using the previous tags file if the new one isn't up to snuff.
Poking around, I found the following code in top.php which is nearly (or maybe exactly) what I need:
if(isset($SITE['WXtags']) and $SITE['WXtags'] <> '') {
// see if upload copy should be done
$siteUploadFile = preg_replace('|\.php$|','-new.php',$SITE['WXtags']);
if(file_exists($siteUploadFile) and
is_writable($SITE['WXtags']) and
filesize($siteUploadFile) > filesize($SITE['WXtags']) - 1023 and
filemtime($siteUploadFile) > filemtime($SITE['WXtags']) ) {
$didCopy = copy($siteUploadFile,$SITE['WXtags']);
if($didCopy) {
print "<!-- WXtags file updated successfully from $siteUploadFile -->\n";
} else {
print "<!-- WXtags file update failed from $siteUploadFile -->\n";
}
}
if (isset($_REQUEST['debug']) and strtolower($_REQUEST['debug']) == 'y') {
$canWriteTags = is_writable($SITE['WXtags'])?"is":"IS NOT";
print "<!-- WXtags '".$SITE['WXtags']. "' $canWriteTags writeable. -->";
}
include_once($SITE['WXtags']);
}
If I'm reading this right, I can change the FTP file name from the meteobridge to MBtags-new.php which would trigger this code, allowing me to add a sanity check for what I'm seeing.
Before digging in, questions (most likely for Ken).
What was the original purpose of this code?
What is the significance of 1023 when comparing the file sizes?
Thanks!!