<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[cURL error: name lookup timed out  这种错误怎么捕获到？linux服务器因nameservers停止工作，导致name lookup timed out的解决方法。 ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Fri, 21 Jun 2013 03:34:26 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：用PHP的Curl调用对方的接口，居然返回 curl error: name lookup timed out，一堆错,显然是服务器间歇性抽风。<br/><br/>strace了下发现：<br/><textarea name="code" class="php" rows="15" cols="100">
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
sendto(3, &quot;GET /user/mobileUserLogin?uid=xd&quot;..., 265, MSG_NOSIGNAL, NULL, 0) = 265
poll([&#123;fd=3, events=POLLIN&#125;], 1, 1000
)&nbsp;&nbsp;= 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 0)&nbsp;&nbsp;&nbsp;&nbsp; = 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 1000
)&nbsp;&nbsp;= 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 0)&nbsp;&nbsp;&nbsp;&nbsp; = 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 1000)&nbsp;&nbsp;= 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 0)&nbsp;&nbsp;&nbsp;&nbsp; = 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 1000)&nbsp;&nbsp;= 0 (Timeout)
poll([&#123;fd=3, events=POLLIN&#125;], 1, 0)&nbsp;&nbsp;&nbsp;&nbsp; = 0 (Timeout)
</textarea><br/><br/><br/>我发现抽风的服务器可以通过--connect-timeout 来减少给接口调用方直接提示：name lookup timed out，<br/>是用curl发现这个问题的：<br/>curl的超时时间设置：<br/>使用curl时，有两个超时时间：一个是连接超时时间，另一个是数据传输的最大允许时间。<br/><br/>连接超时时间用 --connect-timeout 参数来指定，数据传输的最大允许时间用 -m 参数来指定。<br/>例如：<br/>curl --connect-timeout 10 -m 20 &quot;http://XXXXXXX&quot;<br/>连接超时的话，出错提示形如：<br/>curl: (28) connect() timed out!<br/>数据传输的最大允许时间超时的话，出错提示形如：<br/>curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received<br/><br/>--connect-timeout时间短，对本机的接口（接口再访问其它域名的机器）多次访问出现几率大：<br/><textarea name="code" class="php" rows="15" cols="100">
curl --connect-timeout 1 &quot;http://***&quot;
</textarea><br/><br/>According to cURL Error Codes, error code 6 stands for Couldn&#039;t resolve host. The given remote host was not resolved.<br/>So I guess your DNS was not propagating properly at times ? <br/><br/><br/>Under the hood, both curl_exec and file_get_contents perform nearly identical operations; they both use libresolv to:<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;connect to a name server<br/>&nbsp;&nbsp;&nbsp;&nbsp;issue a dns request<br/>&nbsp;&nbsp;&nbsp;&nbsp;process the dns response<br/><br/>To further debug this, you can use curl_getinfo() to get detailed statistics about your requests; you can use this to get an idea of how long each part took using:<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;CURLINFO_NAMELOOKUP_TIME<br/>&nbsp;&nbsp;&nbsp;&nbsp;CURLINFO_CONNECT_TIME<br/>&nbsp;&nbsp;&nbsp;&nbsp;CURLINFO_PRETRANSFER_TIME<br/>&nbsp;&nbsp;&nbsp;&nbsp;...<br/><br/><br/> The value of<br/>the ptr variable is &quot;name lookup timed out&quot;.<br/><br/>I am using the curl_easy interface. I am *not* setting<br/>CURLOPT_NOSIGNAL, and I am also *not* setting any timeout options<br/>(such as CURLOPT_TIMEOUT). My guess is that this crash is caused by a<br/>signal that is emitted. I suspect that I need to set CURLOPT_NOSIGNAL<br/>to 1L and then configure libcurl to use c-ares. <br/><br/><br/>---------------------------------------------------------------------------------------<br/>linux服务器因nameservers停止工作，导致name lookup timed out的解决方法。<br/><br/>刚服务器上的所有在线代理网站突然出现name lookup timed out问题，网上搜索了一下原来是服务器的nameservers问题，打开/etc/resolv.conf,看到<br/><br/>search box.net<br/>nameserver 66.90.68.15<br/>nameserver 66.90.68.169 v. m$ V- V% d, p% d, e<br/>8 &#123;; n5 t: M) Z% W<br/>ping了下66.90.68.15果然不工作了! k4 v! @: x, ]3 &#92;6 Y, ]0 ?0 n<br/>* K, `5 n( m/ H7 X&amp; B+ ]- n2 a<br/>随便在google里输入“free nameservers”找到这家9 U/ J% b. ]* O* E# i, &#92;&#039; [<br/>http://www.resolvingnameserver.com/freerns.html<br/>Our current set of name servers that you can use are:+ F6 I# b3 s, L* &#124;! F<br/>205.234.170.215<br/>205.234.170.217<br/>打开resolv.conf，替换掉原来的IP，上传。- t) x0 &#92;! j8 y<br/>8 K&quot; g8 e; x) T&quot; k6 d: e<br/>重启下服务器，问题解决。<br/>( s8 r: &#123;0 P$ D) r&amp; j; I7 Q<br/>其实还有一家比较有名的我以前介绍过<br/>http://www.opendns.com/<br/>208.67.222.222<br/>208.67.220.220<br/>我自己的windows计算机上用过，不过如果网站打开慢的话会出现他们的广告，不是很爽，希望使用的这家不要出现这样的情况。<br/>) E, ]+ k8 _1 X<br/>2009年3月25日更新：9 F8 ~. O3 c6 U6 f<br/>205.234.170.215<br/>205.234.170.217<br/>有点慢，有时还是会出现“name lookup timed out”的情况，所以我还是选择了5 &#125;&amp; D5 k% s8 F7 V<br/>208.67.222.222<br/>208.67.220.220<br/><br/>来自：http://www.9125.info/redirect.php?fid=5&amp;tid=286&amp;goto=nextnewset
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] cURL error: name lookup timed out  这种错误怎么捕获到？linux服务器因nameservers停止工作，导致name lookup timed out的解决方法。 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>