PHP以输出缓冲的形式提供了一种非常简单的动态缓存解决方案.如果在最近5分钟内缓存了该站点的首页(生成最多流量),则现在可以从缓存副本提供.
原文链接:https://www.f2er.com/php/240100.html<?PHP $cachefile = "cache/".$reqfilename.".html"; $cachetime = 5 * 60; // 5 minutes // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); echo "<!-- Cached ".date('jS F Y H:i',filemtime($cachefile))." -->n"; exit; } ob_start(); // start the output buffer ?> .. Your usual PHP script and HTML here ... <?PHP // open the cache file for writing $fp = fopen($cachefile,'w'); // save the contents of output buffer to the file fwrite($fp,ob_get_contents()); // close the file fclose($fp); // Send the output to the browser ob_end_flush(); ?>
这是一个简单的缓存类型,
你可以在这里看到它
http://www.theukwebdesigncompany.com/articles/php-caching.php
你可以使用Smarty有缓存技术