Page 1 of 1

USNO-sunmoon error messages

Posted: Fri 23 Nov 2018 5:15 pm
by aznetcowboy
All of a sudden I am getting this error messages today:

Warning: Invalid argument supplied for foreach() in /home/gydfbaoo/public_html/get-USNO-sunmoon.php on line 360

Warning: Invalid argument supplied for foreach() in /home/gydfbaoo/public_html/get-USNO-sunmoon.php on line 371


What is causing this and what do I do to correct it? I have changed nothing in this script or any script for at least a couple months and then it was just for upgrades/updates.

Re: USNO-sunmoon error messages

Posted: Fri 23 Nov 2018 5:55 pm
by saratogaWX
It looks like the USNO has switched to HTTPS today.

Code: Select all

<!-- curl fetching 'http://api.usno.navy.mil/rstt/oneday?date=11/23/2018&coords=32.2217,-110.84444&tz=-7' -->
<!-- HTTP stats:  RC=301 dest=199.211.133.93 port=80 (from sce=23.254.240.227)
      Times: dns=0.000 conn=0.053 pxfer=0.053 get=0.059 total=0.112 secs -->
<!-- headers returned:
HTTP/1.1 301 Moved Permanently
Date: Fri, 23 Nov 2018 17:51:59 GMT
Server: Apache
Location: https://api.usno.navy.mil/rstt/oneday?date=11/23/2018&coords=32.2217,-110.84444&tz=-7
Content-Length: 301
Content-Type: text/html; charset=iso-8859-1
 -->
Change get-USNO-sunmoon.php from

Code: Select all

  $USNOUrl = "http://api.usno.navy.mil/rstt/oneday?date=$lclToday&coords=$myLat,$myLong&tz=$myTZOffset";
to

Code: Select all

  $USNOUrl = "https://api.usno.navy.mil/rstt/oneday?date=$lclToday&coords=$myLat,$myLong&tz=$myTZOffset";

Re: USNO-sunmoon error messages

Posted: Fri 23 Nov 2018 6:12 pm
by saratogaWX
I've released V3.02 with the https fix .. available now from the update tool page 23-Nov-2018, Base=*, Plugin-*

Re: USNO-sunmoon error messages

Posted: Thu 20 Dec 2018 4:06 pm
by aznetcowboy
saratogaWX wrote: Fri 23 Nov 2018 6:12 pm by saratogaWX » Fri Nov 23, 2018 11:12 am
I've released V3.02 with the https fix .. available now from the update tool page 23-Nov-2018, Base=*, Plugin-*
I did the update as you suggested and it has been working okay ever since... that is until today. This morning I am getting the error as follows:
Warning: Invalid argument supplied for foreach() in /home/gydfbaoo/public_html/get-USNO-sunmoon.php on line 361

Warning: Invalid argument supplied for foreach() in /home/gydfbaoo/public_html/get-USNO-sunmoon.php on line 372


This is confusing. Do I need to go after another update? :?

Re: USNO-sunmoon error messages

Posted: Thu 20 Dec 2018 4:56 pm
by saratogaWX
No, no need to update the script. Your site is reporting
<!-- get-USNO-sunmoon.php - Version 3.02 - 23-Nov-2018 -->
<!-- refetch seconds=1 -->
<!-- loading ./cache/USNO-moondata.txt from https://api.usno.navy.mil/rstt/oneday?d ... 4444&tz=-7 -->
<!-- curl fetching 'https://api.usno.navy.mil/rstt/oneday?d ... 4444&tz=-7' -->
<!-- curl Error: Connection timed out after 30001 milliseconds -->
<!-- HTTP stats: RC=0 dest= port=0 (from sce=)
Times: dns=0.003 conn=0.000 pxfer=0.000 get=30.002 total=30.002 secs -->
<!-- headers returned:

-->
<!-- Error loading from USNO API, cache not saved -->
<!-- loading finished. -->
<!-- processing JSON entries for Moon data -->
<!-- json_decode returns - Syntax error, malformed JSON -->
With the USNO having issues, just add (or change) your Settings.php to have

Code: Select all

$SITE['useUSNO'] = false;
to switch to the built-in calculations instead of using the USNO.

Re: USNO-sunmoon error messages

Posted: Fri 21 Dec 2018 4:24 pm
by ConligWX
just reported this over on your forums Ken.

https://www.wxforum.net/index.php?topic ... #msg366210

Re: USNO-sunmoon error messages

Posted: Sat 22 Dec 2018 6:51 pm
by aznetcowboy
ConligWX wrote: Fri 21 Dec 2018 4:24 pm by ConligWX » Fri Dec 21, 2018 9:24 am
just reported this over on your forums Ken.

https://www.wxforum.net/index.php?topic ... #msg366210
While this sounds good (maybe even great), where does the code

} else {
$Debug.= "<!-- Error loading from USNO API, cache not saved -->\n";
return ("");
}


get placed :roll: ?

Re: USNO-sunmoon error messages

Posted: Sat 22 Dec 2018 8:18 pm
by BCJKiwi
PLEASE DISREGARD THIS SUGGESTION.
There are a couple of other changes required elsewhere to properly implement this modification.
BCJKiwi

Ken has given you the clue.
Provided you are using ver 3.02 of the script as recommended, you can switch between using USNO or built-in code. The built-in code does not provide all the variables that USNO does but sufficient for the standard website templates.

Instead of adding
return ("");

you can instead add
$useUSNO = false; // USNO fetch/process failed, set switch to false to use built-in calculations

As to where to do this, search for
$Debug.= "<!-- Error loading from USNO API
which is at line 164 in the original ver 3.02 get_USNO-sunmoon.php file

INSERT the new code on a new line immediately after the original line 164

Using this method, the normal operation will be to use USNO but if there is a problem accessing that data, then the built in calculations will be used automatically. Of course you could just switch to he built-in calculations permanently as suggested by Ken.

Re: USNO-sunmoon error messages

Posted: Sat 22 Dec 2018 9:15 pm
by saratogaWX
I suggest it is better long-term to leave the basic script unmodified (so you can just replace it when it has a new release in the future) and to instead use the Settings.php entry to switch to internal calculations. If you are not into code compare old vs. new and refitting your mods, the Settings.php method is the way to have the least issues when updates are needed.

Re: USNO-sunmoon error messages

Posted: Fri 21 Jun 2019 10:03 am
by Mark14
I have similar problem even after updating the script: http://serwer1823145.home.pl/check-fetch-times.php

For a week following message has popped up:
Warning: Invalid argument supplied for foreach() in /get-USNO-sunmoon.php on line 361

Warning: Invalid argument supplied for foreach() in /get-USNO-sunmoon.php on line 372
How to fix it?

Re: USNO-sunmoon error messages

Posted: Fri 21 Jun 2019 2:30 pm
by saratogaWX
The api.usno.navy.mil site seems to be having issues for a couple of days.

Add

Code: Select all

$SITE['useUSNO'] = false;
to your Settings.php to force using the internal moon calculations instead of the USNO for moon data.