I have a simple PHP program that list some topics.
for example I have an array [1] => Red [2] => Green [3] => Blue
and then I want to get pictures of those three using, say Google API
So I will do this
foreach ($array as $arr)
{
echo curl_get_image($arr);
}
So my problem here is that I'm not only have 3 items in the array, it can be 10 or 20 The program run really slowly, I suspect that it is because 开发者_运维问答the program has to wait for each curl request before going to the next curl request.
what is the best way to do this?
or is there any better way like multithreading the curl processes to run each process in parallel?
Thank You
The best way to do something like this is with curl_multi_init
. There's a simple example provided in the documentation that sends 2 cURL requests at the same time. You could easily implement something that does as many requests in parallel as you want.
精彩评论