PHP cURL consistently taking 15s to resolve DNS

前端 未结 3 1934
遇见更好的自我
遇见更好的自我 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:33

    The problem was an IPv6 lookup failing on my machine. The solution:

    Changed /etc/resolv.conf to:

    nameserver 8.8.8.8
    nameserver 8.8.4.4
    

    After rebooting, resolv.conf got overwritten, so adding this line to /etc/sysconfig/network-scripts/ifcfg-eth0 (which was using BOOTPROTO=dhcp) fixed the problem:

    PEERDNS=no
    

    And everything now works like a charm.

    As an alternative, if you experience this problem on a server on which you can not change the configuration, configure cURL this way:

    curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    

提交回复
热议问题