Author Topic: detecting corrupted tags file  (Read 509 times)

0 Members and 1 Guest are viewing this topic.

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
detecting corrupted tags file
« on: December 28, 2018, 10:46:03 AM »
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:

Code: [Select]
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:

Code: [Select]
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!!
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: detecting corrupted tags file
« Reply #1 on: December 28, 2018, 10:52:08 AM »
The original (and continuing) purpose of the code was to try to avoid tags PHP errors due to incomplete FTP uploads at the time the website is trying to include() the tags file.

Yes, Just upload MBtags-new.php instead of MBtags.php to engage this feature in the template.

The 1023 is just a one 'block'.. if the file uploaded is within one block of the old file, we use it.

This is just a workaround for slow/incomplete FTP-upload issues..

Hope this helps.
« Last Edit: December 28, 2018, 10:54:40 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: detecting corrupted tags file
« Reply #2 on: December 28, 2018, 10:57:01 AM »
Perfect. Particularly since I don't have to write any code!  :grin:

Thanks!
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: detecting corrupted tags file
« Reply #3 on: January 01, 2019, 07:54:23 PM »
One little mod I needed to make to include-wxstatus.php to get the last FTP time displayed correctly (would otherwise use the time the file was copied from the "-new" file):

Code: [Select]
  $siteUploadFile = preg_replace('|\.php$|','-new.php',$SITE['WXtags']);
  if(file_exists($siteUploadFile) )
    do_check($SITE['WXsoftwareLongName']." ".langtransstr("last FTP"), $siteUploadFile,
             60*5+15,'file');
  else
    do_check($SITE['WXsoftwareLongName']." ".langtransstr("last FTP"),$SITE['WXtags'],60*5+15,'file');
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

 

anything