Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $curlInits = array();
- $mh = curl_multi_init();
- $urls = array(
- "http://www.google.co.uk",
- "http://www.reddit.com"
- );
- $key = 0;
- foreach ( $urls as $link)
- {
- $curlInits[$key] = curl_init();
- curl_setopt($curlInits[$key], CURLOPT_URL, $link);
- curl_setopt($curlInits[$key], CURLOPT_RETURNTRANSFER, 1);
- curl_multi_add_handle($mh,$curlInits[$key]);
- $key++;
- }
- $active = 1;
- do {
- $mrc = curl_multi_exec($mh, $active);
- } while ($mrc == CURLM_CALL_MULTI_PERFORM);
- while ($active && $mrc == CURLM_OK) {
- if (curl_multi_select($mh) != -1) {
- do {
- $mrc = curl_multi_exec($mh, $active);
- } while ($mrc == CURLM_CALL_MULTI_PERFORM);
- }
- }
- $results = array();
- $key = 0;
- foreach($urls as $link)
- {
- $response = curl_multi_getcontent( $curlInits[$key] );
- // Add to results array
- $results[] = $response;
- $key++;
- }
- curl_multi_close($mh);
- print_r($results);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement