After finally developing some efficient cache-friendly coding for my site on my local server, it seems that it doesn't work at all when I upload it to my server here. Here is a sample of a css file that I've made.
Now this script should check if the last modified headers are the same or the generated etag are the same as the requested ones and send out the proper 304 response. This method seems to work on my php 4.3.6/apache 2.0.49 server, however, when I test it here, and check my logs, apache is always sending out 200 http ok respoonse instead of 304. I checked to make sure it sent 304 responses by just doing "if (1==1) header("HTTP/1.1 304 Not Modified");" which worked.
I've tried echoing the values, which is only possible when I comment out the first ob_end_flush and they seem to be correct. Maybe I am not doing this buffering thing correctly. I'm new to using buffers.
So I'm really at a loss now. Is there a problem with my script?
Thanks!
PHP Code:
<?
header( "Content-Type: text/css" );
ob_start();
ob_start("ob_gzhandler");
?>
body {
color: black;
margin: 0;
etc. etc.
}
<?
ob_end_flush(); //gzip end_flush
@clearstatcache();
$mtime=filemtime($_SERVER["SCRIPT_FILENAME"]);
$gmt_mtime = gmdate("D, d M Y H:i:s",$mtime) . " GMT";
$size=ob_get_length();
$cache_etag="\"".md5($size)."\"";
header("Last-Modified: $gmt_mtime");
header("Content-Length: $size");
header("ETag: $cache_etag");
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if ($_SERVER['HTTP_IF_NONE_MATCH'] == $cache_etag ) {
header("HTTP/1.1 304 Not Modified");
ob_end_clean();
exit();
}
}
else if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
header("HTTP/1.1 304 Not Modified");
ob_end_clean();
exit();
}
}
/*echo $_SERVER['HTTP_IF_NONE_MATCH'] ."http";
echo $_SERVER['HTTP_IF_MODIFIED_SINCE']. "http";
echo $cache_etag. "cache etag";
echo $gmt_mtime. "mtime";*/
ob_end_flush();
?>
I've tried echoing the values, which is only possible when I comment out the first ob_end_flush and they seem to be correct. Maybe I am not doing this buffering thing correctly. I'm new to using buffers.
So I'm really at a loss now. Is there a problem with my script?
Thanks!
You might check to make sure all those HTTP_ constants are availiable on the Dathorn server?
I guess something in there needed to be added.
Comment