PHP 简单的PHP页面缓存技术

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 简单的PHP页面缓存技术相关的知识,希望对你有一定的参考价值。

<?php
    // define the path and name of cached file
    $cachefile = 'cached-files/'.date('M-d-Y').'.php';
    // define how long we want to keep the file in seconds. I set mine to 5 hours.
    $cachetime = 18000;
    // Check if the cached file is still fresh. If it is, serve it up and exit.
    if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
    include($cachefile);
        exit;
    }
    // if there is either no file OR the file to too old, render the page and capture the HTML.
    ob_start();
?>
    <html>
        output all your html here.
    </html>
<?php
    // We're done! Save the cached content to a file
    $fp = fopen($cachefile, 'w');
    fwrite($fp, ob_get_contents());
    fclose($fp);
    // finally send browser output
    ob_end_flush();
?>

以上是关于PHP 简单的PHP页面缓存技术的主要内容,如果未能解决你的问题,请参考以下文章

简单的PHP页面缓存技术

PHP网页缓存技术

PHP缓存技术

php缓存技术总结

PHP 简单的页面缓存

PHP 带缓存的简单下载页面