【发布时间】:2015-01-30 19:50:57
【问题描述】:
我正在为我的项目开发一个 SEO 系统,并正在优化单个页面的所有链接。
摘自.htaccess文件:
RewriteRule ^(.+)$ seo.php [L,QSA]
此 SEO 文件 (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()?
【问题讨论】:
-
include('cat.php?catid=1')根本不应该工作,因为 PHP 会将其视为本地文件系统操作,而不是使用 http 请求。你真的有一个本地文件名cat.php?catid=1吗?本地文件系统选项不使用查询字符串。 -
似乎
include工作速度快了大约 8 毫秒。但是我只测试了3次(打开的页面)
标签: php include file-get-contents