简单的PHP页面缓存技术

Posted

tags:

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

  1. <?php
  2. // define the path and name of cached file
  3. $cachefile = 'cached-files/'.date('M-d-Y').'.php';
  4. // define how long we want to keep the file in seconds. I set mine to 5 hours.
  5. $cachetime = 18000;
  6. // Check if the cached file is still fresh. If it is, serve it up and exit.
  7. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  8. include($cachefile);
  9. }
  10. // if there is either no file OR the file to too old, render the page and capture the html.
  11. ?>
  12. <html>
  13. output all your html here.
  14. </html>
  15. <?php
  16. // We're done! Save the cached content to a file
  17. $fp = fopen($cachefile, 'w');
  18. fclose($fp);
  19. // finally send browser output
  20. ?>

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

简单的PHP页面缓存技术

PHP网页缓存技术

PHP缓存技术

php缓存技术总结

php最基本的缓存之一页面缓存

PHP 简单的页面缓存