Situation
I have a cache designed for my website where I am currently checking every page request to see if there is a static cached version of the page, and then, if the browser is supported, I browse the page and pass it back to the browser.
Current code
$hash = md5('http://mydomain.com'.$url); $fl = substr($url, 1, 1); if(file_exists('/home/myaccount/public_html/cache/'.$fl.'/'.$hash.'.html') && $_GET['cache'] != 'off' && $fl!=''): ob_start("ob_gzhandler"); header('Content-type: text/html; charset=utf-8'); include 'cache/'.$fl.'/'.$hash.'.html'; elseif(file_exists('/home/myaccount/public_html/cache/'.$hash.'.html') && $_GET['cache'] != 'off'): ob_start("ob_gzhandler"); header('Content-type: text/html; charset=utf-8'); include 'cache/'.$hash.'.html'; else: $_SERVER['REQUEST_URI'] = str_replace('?cache=off','',$_SERVER['REQUEST_URI']); include 'interface/index.php'; endif;
Desired Change
I would like to change it so the files on the server are already uploaded. I already know how to gzip files and install them on the server. However, I would like to know how to change this part of the script so that it checks to see if gzip is supported by the browser and then just passes them the version of the gzipped file. If it is not supported, it will disable it and return it back to the server.
goal
This will do a few things. First, it will use less server space to store files. Secondly, it will trim a few milliseconds from then, without having to use them in every page request, since most browsers will accept the gzipped format. Instead, it will only have un-gzip files for very few unsupported browsers. Thirdly, it is an opportunity to learn more about how php works with gzipped files.
source share