English 中文(简体)
PHP/curl: 名称查找_时间/拖慢请求
原标题:PHP/curl: namelookup_time/dns slowing requests

找到原因的一部分,请看底部

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 , 如建议的条款 。

http://community.centrify.com/t5/Express-for-Mac-Tips-and-Tricks/Using-loc-domains- with-Centrify-Directcontrol-on-the-Mac/ba-p/3724

我确认我的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).

最佳回答

PHP App 代码使用 curl_multi_select, 默认超时为 1 秒。 更改此延迟为 0.0005 秒后, 调用返回速度会更快。 因此造成延迟的原因就是如此。 然而, 我尚不知道 Linux vs OSX 或我所建造的php/libcurl 的特定口味( 5. 3. 8) 为何不同 。

我将另开一个问题, 试图解决曲线- 多重选择问题。

问题回答

您可以在 / etc/ hosts 中固定您的域名, 然后phpcurl 不需要查找 DNS 来找到 ip 地址。 这对我有效 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签