<?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的超时时间 ：curl如果需要进行毫秒超时，cURL 7.16.2中被加入，从PHP 5.2.3起可使用。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Tue, 27 Aug 2013 09:00:28 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<textarea name="code" class="php" rows="15" cols="100">curl -o x.log&nbsp;&nbsp;--connect-timeout 5 -m 1 -i &quot;http://jackxiang.com/interact/getMyActs?uid=20099836&amp;page=1&amp;pagesize=4&quot;</textarea><br/><br/>curl如果需要进行毫秒超时，需要增加：<br/>curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);&nbsp;&nbsp;<br/>或者是：<br/>curl_setopt ( $ch,&nbsp;&nbsp;CURLOPT_NOSIGNAL, true); 是可以支持毫秒级别超时设置的 <br/>[codes=php]<br/>&lt;?php&nbsp;&nbsp;<br/>if (!isset($_GET[&#039;foo&#039;])) &#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Client&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ch = curl_init(&#039;http://example.com/&#039;);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_NOSIGNAL, 1);&nbsp;&nbsp;&nbsp;&nbsp;//注意，毫秒超时一定要设置这个&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);&nbsp;&nbsp;//超时毫秒，cURL 7.16.2中被加入。从PHP 5.2.3起可使用&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data = curl_exec($ch);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_errno = curl_errno($ch);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_error = curl_error($ch);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($curl_errno &gt; 0) &#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;cURL Error ($curl_errno): $curl_error&#92;n&quot;;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; else &#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Data received: $data&#92;n&quot;;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;<br/>&#125; else &#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Server&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(10);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Done.&quot;;&nbsp;&nbsp;<br/>&#125;&nbsp;&nbsp;<br/>?&gt;&nbsp;&nbsp;<br/>[/code]<br/><br/>来自：http://developer.51cto.com/art/201208/351996_2.htm<br/><br/>curl的超时时间 ：<br/>今天在一台服务器上突然看到一个curl进程已经运行了28天还木结束，　有点奇怪！　我在使用curl的时候也设置了超时时间， --connect-timeout 5<br/>curl --connect-timeout 5 --data-binary &quot;set=$&#123;L_UPLOAD_DATA_ENCODED&#125;&quot; http://172.88.99.00:8080/xxx.php &amp;&gt;/dev/null<br/>按理来说， 应该是5s就会超时退出了！&nbsp;&nbsp;纳闷之余想起wget好像对超时时间， 是有分阶段的， 比如说请求的超时， 传输的超时等等， 所以就仔细查看了下curl的手册页：<br/>原来使用curl时，有两个超时时间：一个是连接超时时间，另一个是整个过程允许的最大时间，<br/>--connect-timeout &lt;seconds&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Maximum time in seconds that you allow the connection to the server to take.&nbsp;&nbsp;This only limits the connection phase, once curl has connected this option is of no more use. See also the -m/--max-time option.<br/>&nbsp;&nbsp;&nbsp;&nbsp;If this option is used several times, the last one will be used.<br/>这个是指定连接超时时间。 如果出错， 提示形如：curl: (28) connect() timed out!<br/> <br/>-m/--max-time &lt;seconds&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Maximum&nbsp;&nbsp;time&nbsp;&nbsp;in seconds that you allow the whole operation to take.&nbsp;&nbsp;This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going down.&nbsp;&nbsp;See also the --connect-timeout option.<br/>&nbsp;&nbsp;&nbsp;&nbsp;If this option is used several times, the last one will be used.<br/>这个是指定最大的允许时间。 出错提示如：curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received<br/><br/> <br/>还可以这样用： curl -o x.log &quot;http://www.yyyy.com&quot; --speed-time 5 --speed-limit 1<br/>是说将url内容保存到x.log中, 如果传输速度小于1字节/秒的状态持续5秒,该连接就会终止.<br/>来自：http://blog.chinaunix.net/uid-20788470-id-1841681.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] curl的超时时间 ：curl如果需要进行毫秒超时，cURL 7.16.2中被加入，从PHP 5.2.3起可使用。]]></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>