<?php
$url = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $url);
$file = $break[count($break) - 1];
$cachefile = 'cached-'.substr_replace($file ,"",-4).'.html';
$cachetime = 18000;
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
echo "<!-- Copia en cache generada ".date('H:i', filemtime($cachefile))." -->\n";
include($cachefile);
exit;
}
ob_start(); // Crear buffer de salida
?>
botton-cache.php:
<?php
// Cachear el contenid del fichero
$cached = fopen($cachefile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Enviar el navegador
?>
Luego en cada página de tu web php poner:
<?php
include("top-cache.php");
...
include("bottom-cache.php"); // al final del documento
?>

No hay comentarios:
Publicar un comentario