This is really annoying me, the php script was working and returning the weather from open weather map but literally all of a sudden the php script takes forever to execute and the following error is produced:
Warning: file_get_contents(http://api.openweathermap.org/data/2.5/weather?lat=&lon=&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070) [function.file-get-contents]: failed to open stream: Connection timed out in /xxx/xxx/public_html/fullweather.php on line 15
Any help would be appreciated. The php script can be viewed below. Only the beginning is important (first 18 lines) but I have included the full thing.
<?php $lat = $_POST["latitude"]; $lon = $_POST["longitude"]; $url="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070"; // Make call with cURL $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER,true); $json = curl_exec($session); $json=file_get_contents($url); $data=json_decode($json,true); class weatherdata { public $temp = ""; public $weather = ""; public $clouds = ""; public $area = ""; public $humidity = ""; public $humidpressure = ""; public $weatherdesc = ""; public $tempmin = ""; public $tempmax = ""; public $windspeed = ""; public $winddirec = ""; } $data1 = $data['main']['temp']; $data2 = $data['weather'][0]['main']; $data3 = $data['clouds']['all']; $data4 = $data['name']; $data5 = $data['main']['humidity']; $data6 = $data['main']['pressure']; $data7 = $data['weather'][0]['description']; $data8 = $data['main']['temp_min']; $data9 = $data['main']['temp_max']; $data10 = $data['wind']['speed']; $data12 = $data['wind']['deg']; $weatherdata = new weatherdata(); $weatherdata->temp = $data1; $weatherdata->weather = $data2; $weatherdata->clouds = $data3; $weatherdata->area = $data4; $weatherdata->humidity = $data5; $weatherdata->humidpressure = $data6; $weatherdata->weatherdesc = $data7; $weatherdata->tempmin = $data8; $weatherdata->tempmax = $data9; $weatherdata->windspeed = $data10; $weatherdata->winddirec = $data12; $output[] = $weatherdata; print(json_encode($output)); ?>
Advertisement
Answer
I think the API was just down, cause the link is working for me right now. Try one more time.