<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://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://jackxiang.com/post//</link>
<title><![CDATA[执行、获取远程代码返回：file_get_contents 超时处理]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 22 Sep 2010 14:12:44 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	file_get_contents() 函数 <br/>定义和用法 <br/>file_get_contents() 函数把整个文件读入一个字符串中。 <br/>和 file() 一样，不同的是 file_get_contents() 把文件读入一个字符串。 <br/>file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持，还会使用内存映射技术来增强性能。 <br/>语法<br/><br/><br/>file_get_contents(path,include_path,context,start,max_length)参数 描述 <br/>path 必需。规定要读取的文件。 <br/>include_path 可选。如果也想在 include_path 中搜寻文件的话，可以将该参数设为 &quot;1&quot;。 <br/>context 可选。规定文件句柄的环境。 <br/>context 是一套可以修改流的行为的选项。若使用 null，则忽略。 <br/>start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。 <br/>max_length 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。 <br/>说明 <br/>对 context 的支持是 PHP 5.0.0 添加的。 <br/>针对超时或页面过慢，一般可采取两个解决方案： <br/>1. 利用file_get_contents()第三个参数 <br/><br/><br/>&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>$url = &quot;http://zhoz.com/zhoz.php&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>$ctx = stream_context_create(array(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>‘http’ =&gt; array(‘timeout’ =&gt; 10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>$result = @file_get_contents($url, 0, $ctx);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>if($result)&#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var_dump($result);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;else&#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo &quot; Buffer is empty&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>?&gt;&nbsp;&nbsp; <br/> <br/><br/>「2009/01/22补记」： <br/>此方法1，我经测试在本地反映良好，但如果在外网测试（环境：中国→美国服务器间）基本都是超时的情况。 <br/>测试了TimeOut基本没有用了，建议以下方式<br/><br/>2. 使用curl扩展库 <br/><br/><br/>&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>$url = &quot;http://zhoz.com/zhoz.php&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>&nbsp;&nbsp;try &#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo date(‘Y-m-d h:i:s’);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo &quot;&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>//$buffer = file_get_contents($url);&nbsp;&nbsp;&nbsp;&nbsp;<br/>$buffer = zhoz_get_contents($url);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo date(‘Y-m-d h:i:s’);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>if(emptyempty($buffer)) &#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo &quot; Buffer is empty&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; else &#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo &quot; Buffer is not empty&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch(Exception $e) &#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>echo &quot;error &quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>function zhoz_get_contents($url, $second = 5) &#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>$ch = curl_init();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_URL,$url);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_HEADER,0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_TIMEOUT,$second);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>$content = curl_exec($ch);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>return $content;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>?&gt;&nbsp;&nbsp;&nbsp;&nbsp;<br/>综述，根据系统环境来选择到底应用哪种方法：<br/><br/><br/>&lt;?php&nbsp;&nbsp; <br/>function vita_get_url_content($url) &#123;&nbsp;&nbsp; <br/>if(function_exists(‘file_get_contents’)) &#123;&nbsp;&nbsp; <br/>$file_contents = file_get_contents($url);&nbsp;&nbsp; <br/>&#125; else &#123;&nbsp;&nbsp; <br/>$ch = curl_init();&nbsp;&nbsp; <br/>$timeout = 5;&nbsp;&nbsp; <br/>curl_setopt ($ch, CURLOPT_URL, $url);&nbsp;&nbsp; <br/>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);&nbsp;&nbsp; <br/>curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);&nbsp;&nbsp; <br/>$file_contents = curl_exec($ch);&nbsp;&nbsp; <br/>curl_close($ch);&nbsp;&nbsp; <br/>&#125;&nbsp;&nbsp; <br/>return $file_contents;&nbsp;&nbsp; <br/>&#125;&nbsp;&nbsp; <br/>?&gt;&nbsp;&nbsp;
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 执行、获取远程代码返回：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://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>