Hi Ken,
Apparently, some time after you added the NWS API option to the METAR code, the NWS changed the return headers to and the code detects a successful fetch as a fail (because only "200" is returned and not "200 OK").
HTTP/2 200
server: nginx/1.16.1
content-type: application/geo+json
last-modified: Wed, 15 Jul 2020 14:09:00 GMT
access-control-allow-origin: *
access-control-allow-headers: Feature-Flags
etc...
It's just a case of stale code. I pulled over the header processing code from advforecast2 and it works for both the API and the NOAA site.
/*
$i = strpos($rawhtml,"\r\n\r\n");
$headers = substr($rawhtml,0,$i-1);
$content = substr($rawhtml,$i+2);
$RC = '';
if (preg_match("|^HTTP\/\S+ (.*)\r\n|",$rawhtml,$matches)) {
$RC = trim($matches[1]);
}
*/
$stuff = explode("\r\n\r\n",$rawhtml); // maybe we have more than one header due to redirects.
$content = (string)array_pop($stuff); // last one is the content
$headers = (string)array_pop($stuff); // next-to-last-one is the headers
preg_match('/HTTP\/\S+ (\d+)/', $headers, $m);
if(isset($m[1]))
$RC = (string)$m[1];
else
$RC = '0';
// if(!preg_match('|200 |',$RC))
if ($RC != "200")
{