Web Weather > Weather Website PHP/AJAX scripting

saveYesterday.php broke with time change

(1/1)

greggw:
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.

saratogaWX:
The saveYesterday.php is fairly simple minded
--- Code: ---<?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";
}
?>
--- End code ---
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: ---59 23 * * * /usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1
--- End code ---
to
--- Code: ---59 * * * * cd $HOME/public_html;/usr/bin/php -q saveYesterday.php >/dev/null 2>&1
--- End code ---
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

greggw:
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?

saratogaWX:

--- Quote from: greggw 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?

--- End quote ---
Yes.. use 59 * * * *  .. I'd reversed the cron time specs in the initial posting.. now corrected.   :oops: #-o

greggw:
It is now working perfectly. Thanks so much for your expert advice.

Navigation

[0] Message Index

Go to full version