0

在我的 php 之前和之后,我有以下块将 php 文件生成的 html 缓存到 html 文件中。当我使用http://domain.com/index.php访问该网站时,它会构建 html 文件并将其放在目录中并为后续请求提供服务。如果我只使用http://domain.com访问该网站,则 html 文件不会写入该目录。使用和不使用 url 中的 index.php 访问是否有区别?我注意到的另一件事是,一旦构建了 html 文件,该文件就会同时用于 index.php 和 /

在 index.php 的开头:

if (file_exists($cachefile)) {
    readfile($cachefile);
    echo "<!-- From Cache -->";
    exit;
}
ob_start(); /*Start the output buffer*/
?>

在 index.php 的末尾:

<?php
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents()); 
fclose($fp);
ob_end_flush(); /* Send the output to the browser */
?>
4

0 回答 0