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?

M.A.K. Ripon
  • 2,070
  • 3
  • 29
  • 47
Simon
  • 5,464
  • 6
  • 49
  • 85
  • Answer of this thread is over here [Multiple API requests](https://stackoverflow.com/questions/34538046/multiple-api-calls-in-a-class/47068115#47068115) – Delickate Nov 02 '17 at 05:24

4 Answers4

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.
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
  • I now use a curl_multi_init for about 10 requests at a time. Takes about 5 for 10 requests =D – Simon Oct 10 '10 at 16:58
8

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

urs_baer
  • 81
  • 1
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://stackoverflow.com/a/21362749/3177302

Community
  • 1
  • 1
abdulwadood
  • 596
  • 6
  • 14
0

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

Sastrija
  • 3,284
  • 6
  • 47
  • 64
cuttinger
  • 109
  • 2