本文章介绍了一个简单的关于php入门篇-缓存技术简单应用,有需要的朋友可以看看,这里是利用了ob_start(); ob_end_flush(); 来实例的,代码如下:
- <?php
-
- $cachefile = 'cached-files/'.date('M-d-Y').'.php';
-
- $cachetime = 18000;
-
- if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
- include($cachefile);
- exit;
- }
-
- ob_start();
- ?>
- <html>
- output all your html here.
- </html>
- <?php
-
- $fp = fopen($cachefile, 'w');
- fwrite($fp, ob_get_contents());
- fclose($fp);
-
- ob_end_flush();
- ?>
|