Take the 2-minute tour ×

I was wondering what the best way to do concurrent HTTP requests in PHP? I have a lot of data to get and i'd rather do multiple requests at once to retrieve it all.

Does anybody know how I can do this? Preferably in an anonymous/callback function mannor...



share|improve this question
Like curl the http extension also provides for concurrent requests, using the HttpRequestPool class (which in turn just uses curl behind the scenes). –  mario Oct 6 '11 at 23:36
Possible duplicate: stackoverflow.com/questions/1240267/… –  igorw Oct 6 '11 at 23:37
add comment

3 Answers

up vote 5 down vote accepted

You can use curl_multi, which internally fires off multiple separate requests under a single curl handle.

But otherwise PHP itself not in any way/shape/form "multithreaded" and will not allow things to run in parallel, except via gross hacks (multiple parallel scripts, one script firing up multiple background tasks via exec(), etc...).

share|improve this answer
add comment

You can try either curl_multi() or use a lower level function socket_select()

share|improve this answer
add comment

you can use HttpRequestPool http://www.php.net/manual/de/httprequestpool.construct.php

$multiRequests = array(
  new HttpRequest('http://www.google.com', HttpRequest::METH_GET),
  new HttpRequest('http://www.yahoo.com', HttpRequest::METH_GET)
  new HttpRequest('http://www.bing.com', HttpRequest::METH_GET)

$pool = new HttpRequestPool();
foreach ($multiRequests as $request)


foreach($pool as $request) 
  echo $request->getResponseBody();
share|improve this answer
add comment

Your Answer


