2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.