Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function addHandle(&$curlHandle,$url)
- {
- $cURL = curl_init();
- curl_setopt($cURL, CURLOPT_URL, $url);
- curl_setopt($cURL, CURLOPT_HEADER, 0);
- curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
- curl_multi_add_handle($curlHandle,$cURL);
- return $cURL;
- }
- //execute the handle until the flag passed to function is greater then 0
- function ExecHandle(&$curlHandle)
- {
- $flag=null;
- do {
- curl_multi_exec($curlHandle,$flag);//fetch pages in parallel
- } while ($flag > 0);
- }
- $list[1] = "http://www.example1.com";
- $list[2] = "ftp://example.com";
- $list[3] = "http://www.example2.com";
- $curlHandle = curl_multi_init();
- for ($i = 1;$i <= 3; $i++)
- $curl[$i] = addHandle($curlHandle,$list[$i]);
- ExecHandle($curlHandle);
- for ($i = 1;$i <= 3; $i++)
- {
- $text[$i] = curl_multi_getcontent ($curl[$i]);
- echo $text[$i];
- }
- for ($i = 1;$i <= 3; $i++)//remove the handles
- curl_multi_remove_handle($curlHandle,$curl[$i]);
- curl_multi_close($curlHandle);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment