PHP cURL consistently taking 15s to resolve DNS

前端 未结 3 1914
遇见更好的自我
遇见更好的自我 2021-01-02 11:53

I\'m running PHP on a CentOS virtual machine under MacOS X, and any cURL request consistently takes 15s to run:

$c =          


        
3条回答
  •  有刺的猬
    2021-01-02 12:31

    There may be something wrong in your system, but I find a way to work around it.

    $urldata = parse_url($yourUrl);  
    $host = $urldata['host'];  
    $ip = gethostbyname($host);  
    $new_Url_dns_resolved = str_replace($host,$ip,$yourUrl);  
    //call the dns resolved url instead of the original url  
    $c = curl_init($new_Url_dns_resolved);
    

提交回复
热议问题