我在两台不同的服务器上有 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
Run Code Online (Sandbox Code Playgroud)
编辑 *******
添加的代码:
$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);
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,我通过添加此选项解决了它:
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
Run Code Online (Sandbox Code Playgroud)