Welcome, guest! Login / Register - Why register?

Paste

N/A
Pasted as PHP by AzeriFire ( 11 years ago )
if (isset($useCache) && $useCache==1) // Is caching enabled for this page at init.php ( main controller for my site)
{
if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="/")  // Is there any URI to cache
{
$cacheName=str_replace('/','-',$_SERVER['REQUEST_URI']); // Replasing all slashes from URI with "-"
$cacheName = substr($cacheName,1); // Removing first unwanted "-" symbol
}
else
{
   $cacheName='site-index.html'; //If there are no URI, this maybe index.html
}
$cacheFile = "cache/{$cacheName}"; // Cache file name now is clean and we can use it
if(!isset($cacheTime)) // I can set different cacheTime for different parts of my site. For sample I use 1 hour caching time for index page
{
$cacheTime = 4 * 60;
}
// Serve the cached file if it is older than $cacheTime
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
&Acirc;&nbsp; &Acirc;&nbsp; include($cacheFile);
&Acirc;&nbsp; &Acirc;&nbsp; exit;
}
// Start the output buffer
ob_start();
}
&Acirc;&nbsp;
&Acirc;&nbsp;
/************** Body of site **************/
&Acirc;&nbsp;
&Acirc;&nbsp;
if (isset($useCache) && $useCache==1) // Firstly we check, is caching enabled for this page, if yes do your best my script:)
{
$cached = fopen($cacheFile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
}

 

Revise this Paste

Parent: 5665
Children: 6407 11425 22776 53435
Your Name: Code Language: