是否存在服务器端包含比PHP更好的选择?

时间:2022-05-12 16:25:34

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.

我问的是其他静态网页,其中包括页眉,页脚等文件。显然,使用PHP构建动态网站最好用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.

我问的是因为我被赋予了更新网站的任务,该网站目前正在使用SSI在不同页面上包含相同的标题。

3 个解决方案

#1


2  

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.

如果您没有在页面中使用任何其他PHP,则使用SSI意味着您的Apache进程不需要加载PHP解释器来生成和提供HTML。

#2


1  

include is not the PHP equivalent of #include virtual, that would be: virtualDocs.

include不是PHP等效的#include virtual,即:virtualDocs。

So it's not only that you can mimic with PHP what SSI directives are doing.

因此,您不仅可以使用PHP模仿SSI指令正在执行的操作。

You can even run PHP through SSI if you have a CGI handler configured. And you can run SSIs if mod_php is enabled.

如果配置了CGI处理程序,甚至可以通过SSI运行PHP。如果启用了mod_php,则可以运行SSI。

So this might be helpful to know if you redesign the current site and probably think about changing away from SSIs.

因此,如果您重新设计当前站点并可能考虑改变SSI,这可能会有所帮助。

See Apache Module mod_include for more details.

有关更多详细信息,请参阅Apache Module mod_include。

#3


0  

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.

在某些情况下,SSI可以真正有用,例如当应用程序缓存已渲染的页面时,您需要清除缓存但不想清除导致简单菜单更改的所有页面。然后你可以用ssi include替换菜单或几个菜单,只需清除更改上的菜单文件就可以保持缓存的页面不变。

#1


2  

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.

如果您没有在页面中使用任何其他PHP,则使用SSI意味着您的Apache进程不需要加载PHP解释器来生成和提供HTML。

#2


1  

include is not the PHP equivalent of #include virtual, that would be: virtualDocs.

include不是PHP等效的#include virtual,即:virtualDocs。

So it's not only that you can mimic with PHP what SSI directives are doing.

因此,您不仅可以使用PHP模仿SSI指令正在执行的操作。

You can even run PHP through SSI if you have a CGI handler configured. And you can run SSIs if mod_php is enabled.

如果配置了CGI处理程序,甚至可以通过SSI运行PHP。如果启用了mod_php,则可以运行SSI。

So this might be helpful to know if you redesign the current site and probably think about changing away from SSIs.

因此,如果您重新设计当前站点并可能考虑改变SSI,这可能会有所帮助。

See Apache Module mod_include for more details.

有关更多详细信息,请参阅Apache Module mod_include。

#3


0  

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.

在某些情况下,SSI可以真正有用,例如当应用程序缓存已渲染的页面时,您需要清除缓存但不想清除导致简单菜单更改的所有页面。然后你可以用ssi include替换菜单或几个菜单,只需清除更改上的菜单文件就可以保持缓存的页面不变。