Hi all,
Can any one help how to chache a web page for 24 hours in PHP
chaching in PHP
Moderator: General Moderators
Code: Select all
header("Expires: " . date("D, j M Y H:i:s", time() + 86400) . " UTC");
header("Cache-Control: Public");
header("Pragma: Public");The above is client cache... I'm sure that's not what you meant but maybe it is. My guess is you are talking serverside caching of dynamic pages.
Code: Select all
<?php
ob_start();
$cache_dir = $_SERVER['DOCUMENT_ROOT'].'/cache/';
$self_cached = $cache_dir.preg_replace('/[^0-9a-zA-Z-_]/', '', $_SERVER['REQUEST_URI']);
if(is_file($self_cached) and (filemtime($self_cached) > strtotime(date('Y-m-d'))))
{
readfile($self_cached);
die;
}
/*
Page content here
*/
$buffer = ob_get_clean();
echo $buffer;
$fp = fopen($self_cached, 'w');
fwrite($fp, $buffer, strlen($buffer));
fclose($fp);
?>-
sathish.hc
- Forum Newbie
- Posts: 15
- Joined: Tue May 23, 2006 2:55 am