curl_multi_exec how to execute it on several ip adresses and get response headers
Hello i have made a curl test on an ip and i could get the response infos( times, response code,...) this time i want to make it work on several ip's in the same time. I found that could be possible with curl_multi_exec, and i found this code:
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
$running = null;
//execute the handles
do {
开发者_运维技巧curl_multi_exec($mh, $running);
} while ($running > 0);
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
But i only get the hole content of the last url entered (CURLOPT_URL, "http://www.php.net/")
and besides, i want the informations abouts the request and response( in curl i used ($infos = curl_getinfo($curl);)
You probably need PHP cURL Class With Multi-Threading
Get it here http://pastebin.com/vBgYDzVu or here http://semlabs.co.uk/assets/files/curl.zip
Ex:
include "curl.php";
$curl = new CURL();
$optsA = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => 0 );
$optsB = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => 0 );
$curl->addSession( "http://siteA.com/scriptA.php", $optsA );
$curl->addSession( "http://siteB.com/scriptB.php", $optsB );
$curl->addSession( "http://siteC.com/scriptC.php", $opts );
$curl->addSession( "http://siteD.com/scriptD.php", $opts );
$curlresult = $curl->exec();
$curl->clear();
$siteA = $curlresult[0]
$siteB = $curlresult[1]
$siteC = $curlresult[2]
$siteD = $curlresult[3]
精彩评论