Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You set up each cURL handle in the same way, then add them to a <code>curl_multi_</code> handle. The functions to look at are the <code>curl_multi_*</code> functions <a href="http://us.php.net/manual/en/ref.curl.php" rel="noreferrer">documented here</a>. In my experience, though, there were issues with trying to load too many URLs at once (though I can't find my notes on it at the moment), so the last time I used <code>curl_mutli_</code>, I set it up to do batches of 5 URLs at a time.</p> <p><strong><em>edit</em></strong>: Here is a reduced version of the code I have using <code>curl_multi_</code>:</p> <p><em>edit</em>: Slightly rewritten and lots of added comments, which hopefully will help.</p> <pre><code>// -- create all the individual cURL handles and set their options $curl_handles = array(); foreach ($urls as $url) { $curl_handles[$url] = curl_init(); curl_setopt($curl_handles[$url], CURLOPT_URL, $url); // set other curl options here } // -- start going through the cURL handles and running them $curl_multi_handle = curl_multi_init(); $i = 0; // count where we are in the list so we can break up the runs into smaller blocks $block = array(); // to accumulate the curl_handles for each group we'll run simultaneously foreach ($curl_handles as $a_curl_handle) { $i++; // increment the position-counter // add the handle to the curl_multi_handle and to our tracking "block" curl_multi_add_handle($curl_multi_handle, $a_curl_handle); $block[] = $a_curl_handle; // -- check to see if we've got a "full block" to run or if we're at the end of out list of handles if (($i % BLOCK_SIZE == 0) or ($i == count($curl_handles))) { // -- run the block $running = NULL; do { // track the previous loop's number of handles still running so we can tell if it changes $running_before = $running; // run the block or check on the running block and get the number of sites still running in $running curl_multi_exec($curl_multi_handle, $running); // if the number of sites still running changed, print out a message with the number of sites that are still running. if ($running != $running_before) { echo("Waiting for $running sites to finish...\n"); } } while ($running &gt; 0); // -- once the number still running is 0, curl_multi_ is done, so check the results foreach ($block as $handle) { // HTTP response code $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); // cURL error number $curl_errno = curl_errno($handle); // cURL error message $curl_error = curl_error($handle); // output if there was an error if ($curl_error) { echo(" *** cURL error: ($curl_errno) $curl_error\n"); } // remove the (used) handle from the curl_multi_handle curl_multi_remove_handle($curl_multi_handle, $handle); } // reset the block to empty, since we've run its curl_handles $block = array(); } } // close the curl_multi_handle once we're done curl_multi_close($curl_multi_handle); </code></pre> <p>Given that you don't need anything back from the URLs, you probably don't need a lot of what's there, but this is how I chunked the requests into blocks of <code>BLOCK_SIZE</code>, waited for each block to run before moving on, and caught errors from cURL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload