我正在为我的项目搜索引擎优化系统工作,并优化了单一页面的所有链接。
摘自.htaccess
文件:
RewriteRule ^(.+)$ seo.php [L,QSA]
这个搜索引擎优化文件(seo.php
)将获得所请求的路径,并将其解析为有效的url到我的脚本。
我在seo.php
的末尾使用了include('cat.php?catid=1')
,一切正常,但我想知道哪个更快:include()
还是file_get_contents()
当我使用file_get_content('cat.php?catid=1')
时,它会显示PHP文件的源代码,但当我使用file_get_content('http://localhost/cat.php?catid=1')
时,它会显示普通页面。
那么,file_get_content()
和include()
哪个更快呢?
发布于 2012-05-03 03:16:51
它们当然是不同的。
PHP将解析it
因此,如果您只想检索页面的html内容,请使用file_get_contents
,否则,如果您需要解析include();
代码,请使用PHP
注意:如果要检索网站上托管的页面的内容,则应使用本地路径而不是指向资源的web路径,即:
file_get_contents('http://example.com/file.html');
:
file_get_contents('/home/user/site/file.html');
发布于 2012-05-03 03:17:18
如果您正在加载自己的本地文件作为模板的一部分,请使用require
或include
。当然,您可以使用require_once
或include_once
,但不要对本地文件使用file_get_contents
。
这与性能没有任何关系,而是关于目的。不存在用于动态加载模板依赖项的file_get_contents
。除非你需要在显示之前解析他们的内容,或者他们在其他领域,这是非常不可能的。
发布于 2012-05-03 03:54:57
因此,代码应该是
include('cat.php');
https://stackoverflow.com/questions/10420175
复制相似问题