是否存在服务器端包含比 PHP 更好的选择的情况?
我问的是有关静态网页的信息,其中包括页眉、页脚等文件。显然,使用 SSI 构建动态网站会更好地使用 PHP。
是否有任何理由可以
<!--#include virtual="../quote.txt" -->
代替
<?php include("../quote.txt"); ?>
(或另一种语言中的等效内容)?
我之所以这么问,是因为我的任务是更新一个网站,该网站当前正在使用 SSI 在不同页面上包含相同的标头。
I'm asking in regards to otherwise-static webpages which include files like headers, footers, etc. Obviously building a dynamic site with SSI would be better done with PHP.
Is there ever any reason to do
<!--#include virtual="../quote.txt" -->
instead of
<?php include("../quote.txt"); ?>
(or the equivalent in another language)?
I'm asking because I've been given the task of updating a website which is currently using SSI for including the same header on different pages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您没有在页面中使用任何其他 PHP,则使用 SSI 意味着您的 Apache 进程不需要加载 PHP 解释器来生成和提供 HTML。
If you're not using any other PHP in the page, using an SSI means your Apache processes don't need to load up the PHP interpreter to generate and serve the HTML.
include
不是 PHP 中的#include virtual
等价物,而是:虚拟
文档。因此,您不仅可以使用 PHP 来模拟 SSI 指令的功能。
如果您配置了 CGI 处理程序,您甚至可以通过 SSI 运行 PHP。如果启用了
mod_php
,您就可以运行 SSI。因此,这可能有助于了解您是否重新设计当前站点并可能考虑放弃 SSI。
有关更多详细信息,请参阅 Apache 模块 mod_include。
include
is not the PHP equivalent of#include virtual
, that would be:virtual
Docs.So it's not only that you can mimic with PHP what SSI directives are doing.
You can even run PHP through SSI if you have a CGI handler configured. And you can run SSIs if
mod_php
is enabled.So this might be helpful to know if you redesign the current site and probably think about changing away from SSIs.
See Apache Module mod_include for more details.
在某些情况下,SSI 确实很有用,例如,当应用程序缓存呈现的页面并且您需要清除缓存但又不想因为简单的菜单更改而清除所有页面时。然后,您可以用 ssi include 替换一个或多个菜单,并在更改时清除菜单文件,并保持缓存的页面完好无损。
There are some circumstances where SSI can really be helpfull e.g. when an application caches rendered pages and you need to clear the cache but don't want to clear all pages cause of a simple menu change. Then you could just replace the menu or several menus by an ssi include and just clear the menu files on a change an leave the cached pages intact.