我在两台不同的服务器上有 example.com,我使用 php curl 连接到一台服务器,执行一些任务,然后尝试连接到另一台服务器并执行其他一些任务,但它第二次不遵守 CURLOPT_RESOLVE正如您在详细输出中看到的那样。
我尝试将 CURLOPT_DNS_CACHE_TIMEOUT 设置为 0,但仍然连接到旧 IP。
知道我该如何解决吗?
不幸的是,我无法直接连接到 ip。
* Added example.com:80:207.230.220.255 to DNS cache
* Hostname was found in DNS cache
* Trying 207.97.92.288...
* Connected to example.com (207.97.92.288) port 80 (#0)
> GET /example.php HTTP/1.1
Host: example.com
Accept: */*
< HTTP/1.1 404 Not Found
< Date: Tue, 05 Apr 2016 18:00:58 GMT
* Server Apache is not blacklisted
< Server: Apache
< Accept-Ranges: bytes
< Transfer-Encoding: chunked
< Content-Type: text/html
<
* Connection #0 to host example.com left intact
编辑 *******
添加代码:
$check_ping_resolve = ["example.com:80:207.230.220.255"];
$check_ping = "http://example.com/123.php";
$check_ping_verbose = fopen(dirname(__FILE__) . '/ping.txt', 'w');
$check_ping_curl = curl_init();
curl_setopt($check_ping_curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($check_ping_curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($check_ping_curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($check_ping_curl, CURLOPT_DNS_CACHE_TIMEOUT, 0);
curl_setopt($check_ping_curl, CURLOPT_RESOLVE, $check_ping_resolve);
curl_setopt($check_ping_curl, CURLOPT_URL, $check_ping);
curl_setopt($check_ping_curl, CURLOPT_VERBOSE, 1);
curl_setopt($check_ping_curl, CURLOPT_STDERR, $check_ping_verbose);
$check_ping_curl_result = curl_exec($check_ping_curl);
最佳答案
我有同样的问题,我通过添加这个选项解决了它:
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
关于PHP curl CURLOPT_RESOLVE 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434049/