Tuesday, June 17, 2014

buat caching full html menggunakan obstart

saat main agc kan sering itu blank skrg dari bing

solusinya kita harus punya caching sendiri yg harus full html biar gag tergantung sama bing
1. cara pake plugin udah ada, http://wordpress.org/plugins/wp-ffpc/ tapi harus bs aktifkan xcahce/memcache
2. pake cara ini taruh di header paling mentok atas
buat folder cahche chmod 777 di root direktory dulu



<?php
//settings cache
$cache_ext  = '.html'; //file extension
$cache_time     = 3600;  //Cache file expires afere these seconds (1 hour = 3600 sec)
$cache_folder   = 'cache/'; //folder to store Cache files
//$ignore_pages   = array('', '');

$dynamic_url    = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING']; // requested dynamic page (full url)
$cache_file     = $cache_folder.md5($dynamic_url).$cache_ext; // construct a cache file
//$ignore = (in_array($dynamic_url,$ignore_pages))?true:false; //check if url is in ignore list

if (file_exists($cache_file) && time() - $cache_time < filemtime($cache_file)) { //check Cache exist and it's not expired.
    ob_start('ob_gzhandler'); //Turn on output buffering, "ob_gzhandler" for the compressed page with gzip.
    readfile($cache_file); //read Cache file
    echo '<!-- cached page - '.date('l jS \of F Y h:i:s A', filemtime($cache_file)).', Page : '.$dynamic_url.' -->';
    ob_end_flush(); //Flush and turn off output buffering
    exit(); //no need to proceed further, exit the flow.
}
//Turn on output buffering with gzip compression.
ob_start('ob_gzhandler');
######## Your Website Content Starts Below #########
?>

No comments:

Post a Comment