我正在尝试为我正在编写的 PHP 脚本实现缓存,但我一直遇到以下问题。我希望脚本包含在其他 PHP 页面中,但是当我尝试传递缓存文件并退出嵌入脚本时,它会同时退出脚本和父页面,但不会解析父页面上的其余代码. 有关示例,请参见下面的代码。
索引.php
<?php
echo "Hello World!<br />";
include("file2.php");
echo "This line will not be printed";
?>
文件2.php
<?php
$whatever = true;
if ($whatever == true) {
echo "file2.php has been included<br />";
exit; // This stops both scripts from further execution
}
// Additional code here
?>
如果上面的 index.php 被执行,你会得到以下输出:
Hello World!
file2.php has been included
但是,我试图让它看起来像这样:
Hello World!
file2.php has been included
This line will not be printed