PHP Multiple Curl Requests
Asked Answered
E

4

36

I'm currently using Curl for PHP a lot. It takes a lot of time to get results of about 100 pages each time. For every request i'm using code like this

$ch = curl_init();

// get source

curl_close($ch);

What are my options to speed things up?

How should I use the multi_init() etc?

Erne answered 10/10, 2010 at 11:44 Comment(1)
Answer of this thread is over here Multiple API requestsSnorter
A
47
  • Reuse the same cURL handler ($ch) without running curl_close. This will speed it up just a little bit.
  • Use curl_multi_init to run the processes in parallel. This can have a tremendous effect.
Ada answered 10/10, 2010 at 11:46 Comment(1)
I now use a curl_multi_init for about 10 requests at a time. Takes about 5 for 10 requests =DErne
X
8

take curl_multi - it is far better. Save the handshakes - they are not needed every time!

Xylophone answered 21/11, 2010 at 18:3 Comment(0)
W
1

when i use code given in "http://php.net/curl_multi_init", response of 2 requests are conflicting. But the code written in below link, returns each response separately (in array format) https://mcmap.net/q/427870/-file_get_contents-from-multiple-url

Wie answered 23/1, 2015 at 9:25 Comment(0)
P
0

or take pcntl_fork, fork some new threads to execute curl_exec. But it's not as good as curl_multi.

Padova answered 6/10, 2011 at 3:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.