<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 如何避免使用php的require_once</title>
	<atom:link href="http://www.ooso.net/archives/394/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ooso.net/archives/394</link>
	<description>Linux + Apache + Mysql + Php + Flash</description>
	<lastBuildDate>Wed, 11 Jan 2012 15:01:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Volcano</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-29389</link>
		<dc:creator>Volcano</dc:creator>
		<pubDate>Thu, 17 Dec 2009 11:44:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-29389</guid>
		<description>在使用了某些php开发框架的情况下，这个情况尤其明显。&lt;a href=&quot;http://t3.dotgnu.info/blog/php/include_once-mostly-harmless.html&quot; rel=&quot;nofollow&quot;&gt;个别版本的apc甚至对include_once没有显著的加速效果&lt;/a&gt;。</description>
		<content:encoded><![CDATA[<p>在使用了某些php开发框架的情况下，这个情况尤其明显。<a href="http://t3.dotgnu.info/blog/php/include_once-mostly-harmless.html" rel="nofollow">个别版本的apc甚至对include_once没有显著的加速效果</a>。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kevin</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-29388</link>
		<dc:creator>kevin</dc:creator>
		<pubDate>Thu, 17 Dec 2009 10:22:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-29388</guid>
		<description>这个几乎不考虑吧，就算require_once慢一些，那也是非常快的。一般站点也会通过apc cache之类来缓存php中间码。

通常来讲require_once成为网站瓶颈的还是很少见的，除非包含成千上万个文件。</description>
		<content:encoded><![CDATA[<p>这个几乎不考虑吧，就算require_once慢一些，那也是非常快的。一般站点也会通过apc cache之类来缓存php中间码。</p>
<p>通常来讲require_once成为网站瓶颈的还是很少见的，除非包含成千上万个文件。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yangphp</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-25316</link>
		<dc:creator>yangphp</dc:creator>
		<pubDate>Thu, 11 Sep 2008 15:42:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-25316</guid>
		<description>博主说的对，，ZEND框架用的就是spl_autoload_register</description>
		<content:encoded><![CDATA[<p>博主说的对，，ZEND框架用的就是spl_autoload_register</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 代码罐头</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23367</link>
		<dc:creator>代码罐头</dc:creator>
		<pubDate>Thu, 22 May 2008 01:25:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23367</guid>
		<description>在意不在意这点性能差别
不是空口说的而已
如果测试结果真的发现瓶颈在require_once这里速度太慢
就可以用博主的方法了.
博主只是提供一个优化方法
并没有说一定要用这种方法去替代require_once
如果只是一个pv量只有几千的网站
自然不用去优化的.</description>
		<content:encoded><![CDATA[<p>在意不在意这点性能差别<br />
不是空口说的而已<br />
如果测试结果真的发现瓶颈在require_once这里速度太慢<br />
就可以用博主的方法了.<br />
博主只是提供一个优化方法<br />
并没有说一定要用这种方法去替代require_once<br />
如果只是一个pv量只有几千的网站<br />
自然不用去优化的.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: volcano</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23250</link>
		<dc:creator>volcano</dc:creator>
		<pubDate>Thu, 15 May 2008 12:26:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23250</guid>
		<description>&lt;code&gt;function __autoload($class){
include_once(”$class.inc.php”);
}&lt;/code&gt;

还是得避免include_once，如果为了减少与其它第三方类库产生冲突的可能，建议不要直接使用__autoload,而是使用spl_autoload_register

&lt;code&gt;set_exception_handler(array(GLog,”reportToPage”));&lt;/code&gt;
这段似乎有误，应该写为：
&lt;code&gt;set_exception_handler(array(&#039;GLog&#039;,”reportToPage”));&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><code>function __autoload($class){<br />
include_once(”$class.inc.php”);<br />
}</code></p>
<p>还是得避免include_once，如果为了减少与其它第三方类库产生冲突的可能，建议不要直接使用__autoload,而是使用spl_autoload_register</p>
<p><code>set_exception_handler(array(GLog,”reportToPage”));</code><br />
这段似乎有误，应该写为：<br />
<code>set_exception_handler(array('GLog',”reportToPage”));</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xling</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23247</link>
		<dc:creator>xling</dc:creator>
		<pubDate>Thu, 15 May 2008 10:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23247</guid>
		<description>define(&quot;PATH_REGULATION&quot;,&quot;~[(\\\\)&#124;(/)]+~&quot;);

define(&quot;DOC_ROOT&quot;,preg_replace(PATH_REGULATION,&#039;/&#039;,$_SERVER[&#039;DOCUMENT_ROOT&#039;]));
define(&quot;SITE_ABS_DIR&quot;,preg_replace(PATH_REGULATION,&#039;/&#039;,dirname(__FILE__)));
define(&quot;SITE_DIR&quot;,preg_replace(PATH_REGULATION,&#039;/&#039;,str_replace(DOC_ROOT,&quot;&quot;,SITE_ABS_DIR)));
define(&quot;MULTIBYTE_LEN&quot;,strlen(&quot;一&quot;));

$includePath = array(
	SITE_ABS_DIR.&quot;/lib&quot;,
	SITE_ABS_DIR.&quot;/lib/api&quot;,
	SITE_ABS_DIR.&quot;/lib/exception&quot;,
	SITE_ABS_DIR.&quot;/lib/model/mo&quot;,
	SITE_ABS_DIR.&quot;/lib/model/vo&quot;
);
set_include_path(join(DIRECTORY_SEPARATOR == &quot;/&quot; ? &quot;:&quot; : &quot;;&quot;,$includePath));

/**
 * 自动载入所需要的类
 * 
 * @param string $class 类名
 * @return void
*/
function __autoload($class){
	include_once(&quot;$class.inc.php&quot;);
}

/**
 * 最外层自定义异常捕获接口
 *
 * @param unknown_type $e
 */
function __exception_handler($e){
	GLog::reportToPage($e);
}


function getLastPage($default = &quot;&quot;){
	if (!empty($_SERVER[&quot;HTTP_REFERER&quot;])) 
		return $_SERVER[&quot;HTTP_REFERER&quot;];
	else
		return $default == &quot;&quot; ? GDir::getRelativePath(&quot;/index.php&quot;) : $default;
}
session_start();

date_default_timezone_set(GConfig::DEFAULT_TIMEZONE );

set_exception_handler(array(GLog,&quot;reportToPage&quot;));
//set_exception_handler(&quot;GLog::reportToPage&quot;); //PHP Version 5.2.1 中，不能这样写
//set_exception_handler(&quot;__exception_handler&quot;);</description>
		<content:encoded><![CDATA[<p>define(&#8220;PATH_REGULATION&#8221;,&#8221;~[(\\\\)|(/)]+~&#8221;);</p>
<p>define(&#8220;DOC_ROOT&#8221;,preg_replace(PATH_REGULATION,&#8217;/',$_SERVER['DOCUMENT_ROOT']));<br />
define(&#8220;SITE_ABS_DIR&#8221;,preg_replace(PATH_REGULATION,&#8217;/',dirname(__FILE__)));<br />
define(&#8220;SITE_DIR&#8221;,preg_replace(PATH_REGULATION,&#8217;/',str_replace(DOC_ROOT,&#8221;",SITE_ABS_DIR)));<br />
define(&#8220;MULTIBYTE_LEN&#8221;,strlen(&#8220;一&#8221;));</p>
<p>$includePath = array(<br />
	SITE_ABS_DIR.&#8221;/lib&#8221;,<br />
	SITE_ABS_DIR.&#8221;/lib/api&#8221;,<br />
	SITE_ABS_DIR.&#8221;/lib/exception&#8221;,<br />
	SITE_ABS_DIR.&#8221;/lib/model/mo&#8221;,<br />
	SITE_ABS_DIR.&#8221;/lib/model/vo&#8221;<br />
);<br />
set_include_path(join(DIRECTORY_SEPARATOR == &#8220;/&#8221; ? &#8220;:&#8221; : &#8220;;&#8221;,$includePath));</p>
<p>/**<br />
 * 自动载入所需要的类<br />
 *<br />
 * @param string $class 类名<br />
 * @return void<br />
*/<br />
function __autoload($class){<br />
	include_once(&#8220;$class.inc.php&#8221;);<br />
}</p>
<p>/**<br />
 * 最外层自定义异常捕获接口<br />
 *<br />
 * @param unknown_type $e<br />
 */<br />
function __exception_handler($e){<br />
	GLog::reportToPage($e);<br />
}</p>
<p>function getLastPage($default = &#8220;&#8221;){<br />
	if (!empty($_SERVER["HTTP_REFERER"]))<br />
		return $_SERVER["HTTP_REFERER"];<br />
	else<br />
		return $default == &#8220;&#8221; ? GDir::getRelativePath(&#8220;/index.php&#8221;) : $default;<br />
}<br />
session_start();</p>
<p>date_default_timezone_set(GConfig::DEFAULT_TIMEZONE );</p>
<p>set_exception_handler(array(GLog,&#8221;reportToPage&#8221;));<br />
//set_exception_handler(&#8220;GLog::reportToPage&#8221;); //PHP Version 5.2.1 中，不能这样写<br />
//set_exception_handler(&#8220;__exception_handler&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xling</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23246</link>
		<dc:creator>xling</dc:creator>
		<pubDate>Thu, 15 May 2008 10:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23246</guid>
		<description>大侠们，分析一下这个文件有何不妥，谢谢：

</description>
		<content:encoded><![CDATA[<p>大侠们，分析一下这个文件有何不妥，谢谢：</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: volcano</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23032</link>
		<dc:creator>volcano</dc:creator>
		<pubDate>Thu, 08 May 2008 06:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23032</guid>
		<description>在大负载的网站上，这些细节会给性能带来很大的影响。</description>
		<content:encoded><![CDATA[<p>在大负载的网站上，这些细节会给性能带来很大的影响。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan.Tan</title>
		<link>http://www.ooso.net/archives/394/comment-page-1#comment-23030</link>
		<dc:creator>Ivan.Tan</dc:creator>
		<pubDate>Thu, 08 May 2008 05:42:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/394#comment-23030</guid>
		<description>呵呵，其实呢，不用十分在意这上面的资源消耗
有关 require 和 require_once 的争议由来已久
并且很早就有人抽象过类似的方法，采用require(absolute_path_to_file)

不过个人还是倾向直接使用 require_once
因为没必要引入多余的东西，给自己带来不必要的麻烦</description>
		<content:encoded><![CDATA[<p>呵呵，其实呢，不用十分在意这上面的资源消耗<br />
有关 require 和 require_once 的争议由来已久<br />
并且很早就有人抽象过类似的方法，采用require(absolute_path_to_file)</p>
<p>不过个人还是倾向直接使用 require_once<br />
因为没必要引入多余的东西，给自己带来不必要的麻烦</p>
]]></content:encoded>
	</item>
</channel>
</rss>

