<?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[file_get_contents超时的问题,php file_get_contents超时处理。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 21 Aug 2008 03:25:36 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<textarea name="code" class="php" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ctx = stream_context_create(array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;http&#039; =&gt; array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;timeout&#039; =&gt; 2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $urlParam=&quot;http://timor.tech/api/holiday/info/&#123;$dateLoopDay&#125;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $holidayRet = file_get_contents($urlParam, 0, $ctx);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$retJson2Arr = json_decode($holidayRet,true);
</textarea><br/><br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;foreach ($bushu_info as $key =&gt; $value)
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$getStr = $key.&quot;=&quot;.$value.&quot;&amp;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;$url = &quot;http://adc.webdev.com?&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$getURlStr = $url.$getStr;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;$context = stream_context_create($opts);
&nbsp;&nbsp;&nbsp;&nbsp;$html =file_get_contents($getURlStr, false, $context);
&nbsp;&nbsp;&nbsp;&nbsp;fpassthru($fp);
</textarea><br/>请有使用file_get_contents的同学在调用前进行设置<br/>ini_set(&#039;default_socket_timeout&#039;, $seconds);<br/>当PHP读取php.ini配置文件中的所有设置信息的同时，它提供了采用ini_set()函数根据per-scrīpt原则更改这些设置的功能。此函数接收两个参数：需要调整的配置变量名，以及变量的新值。<br/>例如，在某脚本出现时增加最大执行时间（maximum execution time）：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;?php
ini_set(&#039;max_execution_time&#039;, 600)
ini_set(&#039;display_errors&#039;,&#039;1&#039;);//php默认是不显示错误的，这样可以把错误设置打开
// more code
?&gt;
</textarea><br/><br/>这样的设置将仅仅影响被设置的脚本。一旦脚本执行完毕，该变量将自动恢复到原始值。<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;?php
$ctx = stream_context_create(array(
&nbsp;&nbsp;&nbsp;&nbsp;&#039;http&#039; =&gt; array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;timeout&#039; =&gt; 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
&nbsp;&nbsp;&nbsp;&nbsp;)
);
file_get_contents(&quot;http://example.com/&quot;, 0, $ctx); 
?&gt;
</textarea><br/><textarea name="code" class="html" rows="15" cols="100">
&lt; ?php
$file_contents = file_get_contents(&#039;http://www.ccvita.com/&#039;);
echo $file_contents;
?&gt;
</textarea><br/>换成curl函数的使用示例: <br/>&lt; ?php<br/>$ch = curl_init();<br/>$timeout = 5; <br/>curl_setopt ($ch, CURLOPT_URL, &#039;http://www.ccvita.com&#039;);<br/>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); <br/>curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);<br/>$file_contents = curl_exec($ch);<br/>curl_close($ch);<br/>echo $file_contents;<br/>?&gt;<br/>file_get_contents来post数据：<br/> HTTP POST with file_get_contents&nbsp;&nbsp;<br/><textarea name="code" class="html" rows="15" cols="100">
$post_variables = array(&#039;usernamed&#039; =&gt; &#039;rasmus&#039;); 
$content = http_build_query($post_variables); 
$content_length = strlen($content); 
$options = array( 
&nbsp;&nbsp;&nbsp;&nbsp;&#039;http&#039;=&gt;array( 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;method&#039;&nbsp;&nbsp;=&gt; &#039;POST&#039;, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;header&#039;&nbsp;&nbsp;=&gt; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Content-type: application/x-www-form-urlencoded&#92;r&#92;n&quot; .&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Content-length: $content_length&#92;r&#92;n&quot;, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;content&#039; =&gt; $content 
&nbsp;&nbsp;&nbsp;&nbsp;) 
); 
$context = stream_context_create($options); 
$index = file_get_contents(&#039;http://www.example.com/index.php&#039;, false, $context); 
</textarea><br/><br/>可以参考：http://hi.baidu.com/lssbing/blog/item/9a2dcb0f1183a1266059f38d.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] file_get_contents超时的问题,php file_get_contents超时处理。]]></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>