function weatherData($date_array){
$weather_array = [];
$url = "http://api.worldweatheronline.com/premium/v1/past-weather.ashx?key=#######&q=frankston&format=json&date=";
// Get cURL resource
array_pop($date_array);
foreach($date_array as $value){
$url2 = $url . $value;
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url2
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
$data = json_decode($resp);
$runningTotal = 0;
for ($i=0; $i < 7; $i++) {
$hourly_data = $data->data->weather[0]->hourly[$i]->precipMM;
$runningTotal += $hourly_data;
}
if($runningTotal >= 0.7){
array_push($weather_array, 'wet <img class="icon" src="images/icons8-Rain-26.png"/>');
} else{
array_push($weather_array, 'dry <img class="icon" src="images/images.png"/>');
}
}
return $weather_array;
Okay, so i have this function that will output an array of weather or not certain dates were 'wet' or 'dry', my problem is if i have maybe 120 dates that i want to do it will take longer than 30 secs in page load time causing a critical error in PHP, so i need some way to bring these synchronous curl requests to some sort of asynchronous form thanks!
ps sorry about that trashy indenting
Note : This is not about speeding up the requests. Taking completely different approach, but it surely solves your PHP timeout error.
Proposed Solution :
It is little wider question. Needs lot of technical explanation and implementation assumptions. I will try to list down main points below:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.