使用php进行页面缓存
发布时间:2020-05-26 02:13:00 所属栏目:PHP 来源:互联网
导读:我正在寻求所有人的指导,他们可以告诉我有关网站的页面缓存…我在php工作,所以如果有人可以解释我如何在 PHP中执行缓存. PHP以输出缓冲的形式提供了一种非常简单的动态缓存解决方案.如果在最近5分钟内缓存了该站点的首页(生成最多流量),则现在可以从缓存副本
|
我正在寻求所有人的指导,他们可以告诉我有关网站的页面缓存…我在php工作,所以如果有人可以解释我如何在 PHP中执行缓存. PHP以输出缓冲的形式提供了一种非常简单的动态缓存解决方案.如果在最近5分钟内缓存了该站点的首页(生成最多流量),则现在可以从缓存副本提供. <?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有缓存技术 http://www.nusphere.com/php/templates_smarty_caching.htm (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
