找到原因的一部分,请看底部
I m doing a standard curl call from php. However, there seems to be a hangup during name resolution. On my OSX box, the namelookup_time is over 1 second consistently for this and other queries to the same subnet. A linux box on my subnet doing the same query has a 0.02 second response to the other subnet, so it s a problem with my box.
这是一个问题,因为我们的应用程序 多次调用这个子网 来建立一个页面, 所以秒加起来。
我的 curl_getinfo 响应( url 剪断)
array
url => string < SNIPPED > ... (length=1449)
content_type => string text/plain; charset=utf-8 (length=25)
http_code => int 200
header_size => int 227
request_size => int 1480
filetime => int -1
ssl_verify_result => int 0
redirect_count => int 0
total_time => float 1.165444
namelookup_time => float 1.001272
connect_time => float 1.017765
pretransfer_time => float 1.017781
size_upload => float 0
size_download => float 92562
speed_download => float 79422
speed_upload => float 0
download_content_length => float 92562
upload_content_length => float 0
starttransfer_time => float 1.043094
redirect_time => float 0
certinfo =>
array
empty
redirect_url => string (length=0)
我怀疑这个名字的查找滞后是IPv6造成的 所以我尝试了以下方法:
(1) 遵循此方向关闭 OSX 上的 Ipv6, 包括重新启动。 我设置了所有 IPv6 的 IPv6 实例到 < 坚固 > imactive strong >, 如建议的条款 。
我确认我的Mac在这里没有IPv6支持:http://ipv6test.google.com/ 。
2) 重新建造的PHP, 配有 -- 残疾人- ipv6。
php - i 显示: IPv6 支持 *gt; 已禁用
虽然在卷曲部分,它写着"IPv6gt;是的",我不知道怎么用手术来关掉它。
3) 在卷发电话拨打之前,
curl_setaopt( 美元, CURLOPT_ IPRESOLVE, CURL_ IPRESOLVE_ V4) ;
但不幸的是,上述步骤都没有奏效 — — 我还有1秒加国名解析时间。 有没有人提出任何解决问题的建议,或者说比这更好的是灵丹妙药? ) :
(注:我用谷歌搜索了这个问题,但毫无用处。 )
Edit: answering ckhan s questions below:
1) I get the same 1 sec+ namelookup_time using an IP address or a FQDN:
url => string HTTP://172.19.105.171:8070 <SNIPPED> ... (length=1439)
...
namelookup_time => float 1.001309
2) 指挥线客户端没有同样的问题:
# url.txt has the same url as the above curl call
time cat url.txt |xargs curl
<... response output ...>
real 0m0.053s
user 0m0.009s
sys 0m0.008s
3⁄4 ̄ ̧漯B
dig 172.19.105.171
...
;; Query time: 77 msec
...
My environment:
PHP 5.3.8
OSX 10.7.3
<强 > 部分解决方案 强 >
The app code is using curl_multi_select, which has a default timeout of 1 second. Changing this delay to 0.00005 seconds makes the call return much faster. So that s what s causing the delay. However, I don t yet know why this is different on Linux vs OSX or the particular flavor of php/libcurl that I have built (5.3.8).