Author Topic: undefined offset..  (Read 827 times)

0 Members and 1 Guest are viewing this topic.

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1043
    • GosportWx.com
undefined offset..
« on: April 12, 2019, 03:14:17 AM »
I'm getting this error "Undefined offset: 1 in /home/hj2ke8lfpx43/public_html/advforecast2.php on line 413" on my main www.gosportwx.com/wxindex.php above my current conditions box.
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: undefined offset..
« Reply #1 on: April 12, 2019, 10:53:26 AM »
Ken will know right away what that is but someone else may be able to help but you're going to need to post the contents of that line.

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: undefined offset..
« Reply #2 on: April 12, 2019, 11:06:46 AM »
Ken will know right away what that is but someone else may be able to help but you're going to need to post the contents of that line.
Posting the line is not necessary for almost all of the modern scripts as they support the "?sce=view" option on the url
That option lists the complete source of the script in your browser.

 www.gosportwx.com/advforecast2.php?sce=view =>  line 143 is:
Code: [Select]
$lastRC = (string)$m[1];And then the author of this script has to find out what the problem is this time with the returned NWS data.

The error only occurs (or is visible) when running the startpage.
http://www.gosportwx.com/advforecast2.php shows no error.

Wim

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: undefined offset..
« Reply #3 on: April 12, 2019, 11:13:38 AM »
Would surrounding the 1 with single quotes make a difference?

Code: [Select]
$lastRC = (string)$m['1'];

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: undefined offset..
« Reply #4 on: April 12, 2019, 11:41:48 AM »
Hmmm... the NWS may be using HTTP/2 responses now.

Try changing advforecast2.php line 410 from
Code: [Select]
  preg_match('/HTTP\/1.1 (\d+)/', $headers, $m);
to
Code: [Select]
  preg_match('/HTTP\/\S+ (\d+)/', $headers, $m);
and see if that gets rid of the Notice erratum.
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: undefined offset..
« Reply #5 on: April 12, 2019, 01:13:53 PM »
There are two lines of debug code right about the one that's giving you the error:

Code: [Select]
//$Status .= "<!-- m=".print_r($m,true)." -->\n";
//$Status .= "<!-- html=".print_r($html,true)." -->\n";

Un-comment those and you'll see the results in a view-source. Should provide a clue as to what's going on.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1043
    • GosportWx.com
Re: undefined offset..
« Reply #6 on: April 12, 2019, 05:49:19 PM »
Hmmm... the NWS may be using HTTP/2 responses now.

Try changing advforecast2.php line 410 from
Code: [Select]
  preg_match('/HTTP\/1.1 (\d+)/', $headers, $m);
to
Code: [Select]
  preg_match('/HTTP\/\S+ (\d+)/', $headers, $m);
and see if that gets rid of the Notice erratum.

Thanks Ken that fixed it :)
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: undefined offset..
« Reply #7 on: April 13, 2019, 11:42:17 AM »
I'm still curious about what was happening because as you said the code worked fine in another context and I'm not getting any errors of that type with the code still saying "1.1".
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: undefined offset..
« Reply #8 on: April 13, 2019, 12:26:08 PM »
I think it depends on the PHP version+curl version whether the query to api.weather.gov results in an HTTP/1.1 or HTTP/2 response.

Looking at the DNS for api.weather.gov shows
Quote
Dig api.weather.gov@208.67.222.222 ...
Recursive queries supported by this server
 Query for api.weather.gov type=255 class=1
  api.weather.gov CNAME (Canonical Name) sancert.weather.gov.edgekey.net


04/13/19 08:58:10 dig sancert.weather.gov.edgekey.net @ 208.67.222.222
Non-authoritative answer
Recursive queries supported by this server
 Query for sancert.weather.gov.edgekey.net type=255 class=1
  sancert.weather.gov.edgekey.net CNAME (Canonical Name) e278.dscg.akamaiedge.net


04/13/19 08:58:20 dig e278.dscg.akamaiedge.net @ 208.67.222.222
Dig e278.dscg.akamaiedge.net@208.67.222.222 ...
Non-authoritative answer
Recursive queries supported by this server
 Query for e278.dscg.akamaiedge.net type=255 class=1
  e278.dscg.akamaiedge.net AAAA (IPv6 Address) 2001:559:19:6083:0:0:0:116
  e278.dscg.akamaiedge.net AAAA (IPv6 Address) 2001:559:19:6081:0:0:0:116
  e278.dscg.akamaiedge.net A (Address) 184.27.36.18
so akamai is actually hosting it, and the akamai server does the response.

HTTP/2 responses are fairly new (spec drafted in 2015) with Apache support in V2.4 and ngnix support in V1.9.5 since Sept 2015.  Not a lot of websites have implemented HTTP/2, but akamai is now offering content that way.
 
PHP support for HTTP/2 has been available since PHP 7.0.7 and cURL 7.43.0
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 saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: undefined offset..
« Reply #9 on: April 13, 2019, 01:10:48 PM »
I've updated advforecast2.php (JSON) to V5.10 with that HTTP/2 fix.
Available via the script page or for Saratoga template users via the update tool with query for Base-USA, Plugin-*, 13-Apr-2019
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