I'm using file_get_contents in my script. First time this function is running, everything is fine. Second time, there is no response (as fare as I can see) and the is running slowly on my webserver. I don't have this problem running locally, only on one.com. The problem seems to have occurred recently.
<?php
$adresse_sok = "https://example.com/adresser/v1/sok?sok=kirkegata&fuzzy=false&&utkoordsys=25833&treffPerSide=1&side=0&asciiKompatibel=true" ;
$adresse_response = file_get_contents($adresse_sok);
$adresse_data = json_decode($adresse_response,true);
$test = $adresse_data['adresser'][0];
$adressetekst = $adresse_data['adresser'][0]['adressetekst'];
$poststed = $adresse_data['adresser'][0]['poststed'];
$lat = round($adresse_data['adresser'][0]['representasjonspunkt']['lat']);
$lon = round($adresse_data['adresser'][0]['representasjonspunkt']['lon']);
$ost = $lat;
$nord = $lon;
$url = "https://gts.nve.no/api/GridTimeSeries/" . $lon . "/". $lat ."/2022-12-24/2022-12-24/sd.json";
// DOES NOT WORK
$response = file_get_contents($url);
$data = json_decode($response,true);
$snodybde = $data['Data'][0];
?>
When adding var_dump($http_response_header);
this is returned:
array(10) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(13) "Server: nginx" [2]=> string(35) "Date: Thu, 24 Nov 2022 10:45:40 GMT" [3]=> string(30) "Content-Type: application/json" [4]=> string(19) "Content-Length: 781" [5]=> string(17) "Connection: close" [6]=> string(30) "Access-Control-Allow-Origin: *" [7]=> string(48) "Access-Control-Allow-Methods: GET, POST, OPTIONS" [8]=> string(112) "Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" [9]=> string(59) "Access-Control-Expose-Headers: Content-Length,Content-Range" }
When doing this from a different server which is returning data, var_dump($http_response_header);
returns:
array(10) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(22) "Cache-Control: private" [2]=> string(45) "Content-Type: application/json; charset=utf-8" [3]=> string(26) "Server: Microsoft-IIS/10.0" [4]=> string(24) "X-AspNetMvc-Version: 5.2" [5]=> string(27) "X-AspNet-Version: 4.0.30319" [6]=> string(21) "X-Powered-By: ASP.NET" [7]=> string(35) "Date: Thu, 24 Nov 2022 10:42:49 GMT" [8]=> string(17) "Connection: close" [9]=> string(19) "Content-Length: 240" }