检查特定 curl 选项的 return 值

Check return value for a specific curl option

我想检查 CURLOPT_DNS_SERVERS option.I 的 return 值,使用 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;
}
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

您可以获得 header 和所有详细信息:

$skip = intval(curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE)); 
$header = substr($response,0,$skip);
$result= curl_getinfo($curl_handle);
$result['header'] = $header;