Author Topic: saveYesterday.php broke with time change  (Read 505 times)

0 Members and 1 Guest are viewing this topic.

Offline greggw

  • Member
  • *
  • Posts: 15
    • ValleWeather
saveYesterday.php broke with time change
« on: March 22, 2023, 11:26:05 AM »
My website is https://valleweather.com. Yesterday data stopped updating at Sat, 11-Mar-2023 11:58pm per the Status Page. I am hosted at GoDaddy and everything was working fine with the cron command 59 23 * * * /usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1. My time zone setting in settings.php is America/Denver. I think GoDaddy hosts the site on a server in Arizona which does not switch to daylight savings time. I am thinking it is a time zone problem. I tried changing the time zone setting in saveYesterday.php to America/Phoenix, but that did not work. Can anyone offer any suggestions on how to correct? Thanks.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9277
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: saveYesterday.php broke with time change
« Reply #1 on: March 22, 2023, 02:54:28 PM »
The saveYesterday.php is fairly simple minded
Code: [Select]
<?php
# saveYesterday script should be run via cron hourly at 58 after the hour.
# it will only do saving of the &#39;yesterday&#39; value if the local time hour is 23
#
# Version 1.00 - 26-Feb-2018 - initial release
#
if(file_exists("Settings.php")) {

include_once("Settings.php");
date_default_timezone_set($SITE[&#39;tz&#39;]);
$Hnow date(&#39;H&#39;);
$doitAnyway = isset($_GET[&#39;force&#39;])?true:false;
if($Hnow == &#39;23&#39; or $doitAnyway) {
  #$tstamp = date(&#39;Y-m-d H:i:s T&#39;);
#echo "saveYesterday.php local time is $tstamp\n";
    
$saveYesterday true;
    include_once(
"AWNtags.php");
return;
} else {
#echo "saveYesterday.php $tstamp notice: Hour=$Hnow is not = 23 .. not running the save.\n";
return;
}

} else {
echo "saveYesterday.php Warning: no Settings.php found.\n";
}
?>
and shouldn't need any changes to it.  The timezone comes from Settings.php setting.  I think what you need to do is change the command from
Code: [Select]
59 23 * * * /usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1 to
Code: [Select]
59 * * * * cd $HOME/public_html;/usr/bin/php -q saveYesterday.php >/dev/null 2>&1 so it runs every hour.  It will only save the values when LOCAL time is 23:59, otherwise it just quietly exits.

On most webservers, the local time is usually UTC (for convenience of the logs/sysadmins) and cron time may not match your timezone setting at all.  That's why running saveYesterday every hour is recommended.

Ed.. I'd reversed the cron time specs..  #-o
« Last Edit: March 22, 2023, 04:41:58 PM 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 greggw

  • Member
  • *
  • Posts: 15
    • ValleWeather
Re: saveYesterday.php broke with time change
« Reply #2 on: March 22, 2023, 04:38:23 PM »
Thanks, Ken. I will try tonight and report back. However, you say to use 59 23 * * * so it runs every hour. Seems that would only run when the minute is 59 and the hour is 23, i.e. once per day. Should I just use 59 * * * * to run every hour?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9277
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: saveYesterday.php broke with time change
« Reply #3 on: March 22, 2023, 04:43:08 PM »
Thanks, Ken. I will try tonight and report back. However, you say to use 59 23 * * * so it runs every hour. Seems that would only run when the minute is 59 and the hour is 23, i.e. once per day. Should I just use 59 * * * * to run every hour?
Yes.. use 59 * * * *  .. I'd reversed the cron time specs in the initial posting.. now corrected.   :oops: #-o
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 greggw

  • Member
  • *
  • Posts: 15
    • ValleWeather
Re: saveYesterday.php broke with time change
« Reply #4 on: March 23, 2023, 12:07:41 PM »
It is now working perfectly. Thanks so much for your expert advice.