好的,这就是我所拥有的:
Apache中的纯.html文件,使用
<html>
<...>
<!--#include virtual="/SSI/ssi_portlet.php" -->
<...>
</html>但结果是:
<html>
<...>
</html>
Content of SSI PHP Script Result而不是:
<html>
<...>
Content of SSI PHP Script Result
<...>
</html>那么,为什么apache要在页面底部添加脚本结果,而不是在调用include标记的地方呢?
Apache是带有PHP版本5.4.4-14+deb7u12的Apache/2.2.22 (Debian)
发布于 2015-07-31 22:59:16
在我的输出HTML中包含一个PHP文件时,我也遇到了这个问题。在使用普通HTML文件重现示例时,我没有遇到任何问题。您的HTML文件是由PHP处理程序处理的吗?
我不知道你是否还在寻找解决方案,因为这个问题是一个老问题,但你或其他任何人都可以尝试我找到的可能的解决方案。
解决方案:
将这些PHP函数添加到您的"ssi_portlet.php“文件:
开头是ob_flush();和ob_end_clean();,结尾是ob_start();。
我已经使用PHP的输出控制函数php.net测试了许多其他组合,这是唯一一个与各种场景一致工作的组合。
在您的示例中,"SSI/ssi_portlet.php“可能如下所示:
<?php
ob_flush(); ob_end_clean();
echo "Content of SSI PHP Script Result";
ob_start();我已经使用运行Apache/2.4.12 (Win32) PHP/5.6.8的XAMPP在Windows上测试了这个解决方案。
原因:
我对为什么会出现这个问题还不太清楚,所以请随时提供帮助。
PHP在包含文件中生成的输出似乎会干扰现有的输出。因为它们都使用缓冲区来输出数据。(有关PHP输出缓冲的更多信息,请参阅本文末尾)
ob_flush();将刷新任何现有输出,ob_end_clean();将清除缓冲区并在关闭时关闭。这将确保它不会干扰任何现有的输出/缓冲区。
ob_start();将确保任何其他SSI包含的PHP文件将正常工作,但它们也应该包含与上面相同的解决方案。
也就是说,SSI includes不应该用于包含大量数据或创建动态页面。因为输出缓冲是一种提高性能的机制,所以关闭输出缓冲不是最好的解决方案。在处理大量输出时肯定不会。为了达到这些目的,最好使用PHP include()。
PHP output_buffering:
PHP可以使用一种叫做输出缓冲的机制,它有一个叫做"output_buffering“的设置,可以有3个可能的值。引用我的php.ini文件:
; Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before pushing that
; data to the client. If your application's output exceeds this setting, PHP
; will send that data in chunks of roughly the size you specify.
; On = Enabled and buffer is unlimited. (Use with caution)
; Off = Disabled
; Integer = Enables the buffer and sets its maximum size in bytes.
output_buffering=4096 https://stackoverflow.com/questions/25638374
复制相似问题