How can I send GET data to multiple URLs at the same time using cURL?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-26T13:42:11Z Indexed on 2010/04/26 13:43 UTC
Read the original article Hit count: 218

Filed under:
|

My apologies, I've actually asked this question multiple times, but never quite understood the answers.

Here is my current code:

while($resultSet = mysql_fetch_array($SQL)){            
$ch = curl_init($resultSet['url'] . $fullcurl); //load the urls and send GET data
            curl_setopt($ch, CURLOPT_TIMEOUT, 2);           //Only load it for two seconds (Long enough to send the data)
            curl_exec($ch);                                 //Execute the cURL
            curl_close($ch);                                //Close it off 
} //end while loop

What I'm doing here, is taking URLs from a MySQL Database ($resultSet['url']), appending some extra variables to it, just some GET data ($fullcurl), and simply requesting the pages. This starts the script running on those pages, and that's all that this script needs to do, is start those scripts. It doesn't need to return any output. Just the load the page long enough for the script to start.

However, currently it's loading each URL (currently 11) one at a time. I need to load all of them simultaneously. I understand I need to use curl_multi_*, but I haven't the slightest idea on how cURL functions work, so I don't know how to change my code to use curl_multi_* in a while loop.

So my questions are:

How can I change this code to load all of the URLs simultaneously? Please explain it and not just give me code. I want to know what each individual function does exactly. Will curl_multi_exec even work in a while loop, since the while loop is just sending each row one at a time?

And of course, any references, guides, tutorials about cURL functions would be nice, as well. Preferably not so much from php.net, as while it does a good job of giving me the syntax, its just a little dry and not so good with the explanations.

© Stack Overflow or respective owner

Related posts about php

Related posts about curl