I'm looking for some help with this cURL problem I have.
I'm experiencing slow response when I'm using the cURL function below. I have a list of about 40 ids that I pass to the function in a for loop - the URL does not change. Once I get the reponse from each id, I store the data I need in a JSON array (to iterate through the JSON array I have another for loop within the id for loop) and echo the result. I am 99% certain I've isolated the issue to cURL as I can see the response requests taking a long time in Chrome Development Tools.
I'm thinking there has to be a better way to do this because it's taking a really long time to complete, getting up to 10 minutes. When I test the requests via Postman or my browser the response is almost instant. I can manually complete getting the resposnes quicker than I can with PHP/cURL.
So, I'm thinking there has to be a better way to do this but I just can't seem to work it out.
public function cURLfunction($url, $id){
//example $url = "https://mywebsite.com/getIdData/";
//example $id = "100569841";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url . "/" . $id);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close ($curl);
return $result;
}//end cURLfunction
Any help is greatly appreciated
Kahlil