我想检查CURLOPT_DNS_SERVERS
选项的返回值。我使用PHP 5.5.20
并在PHP 5.5.0中添加了此选项。这是我的代码
function do_web_request($url)
{
$dns_array = array("8.8.8.8","209.244.0.3","84.200.69.80","84.200.69.80","8.26.56.26","208.67.222.222","156.154.70.1","199.85.126.10","81.218.119.11","195.46.39.39","107.150.40.234","208.76.50.50","216.146.35.35","37.235.1.174","89.233.43.71");
$randomDNS = $dns_array[array_rand($dns_array, 1)];
/* initializing curl */
$curl_handle = curl_init($url);
/* set this option the curl_exec function return the response */
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
/* follow the redirection */
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_handle, CURLOPT_DNS_SERVERS , $randomDNS);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT , 5);
/* invoke the request */
$response = curl_exec($curl_handle);
/* cleanup curl stuff */
curl_close($curl_handle);
return $response;
}
答案 0 :(得分:1)
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
您可以获取标题和所有详细信息:
$skip = intval(curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE));
$header = substr($response,0,$skip);
$result= curl_getinfo($curl_handle);
$result['header'] = $header;