gpt4 book ai didi

php - 什么更快 : include() or file_get_contents()?

转载 作者:可可西里 更新时间:2023-11-01 13:16:34 24 4
gpt4 key购买 nike

我正在为我的项目开发 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 将解析其中的 PHP 代码
  • file_get_contents 将只返回内容

因此,如果您只想检索页面的 html 内容,请使用 file_get_contents 否则,如果您需要解析 PHP 代码,请使用 include();

注意:如果您想检索托管在您网站上的页面的内容,您应该使用本地路径而不是资源的 Web 路径,即:

  • 执行:file_get_contents('/home/user/site/file.html');
  • 不要:file_get_contents('http://example.com/file.html');

关于php - 什么更快 : include() or file_get_contents()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10420175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com