viewtopic.php?t=35498&highlight=
My problem was too many bots coming to one of my sites at the same time, and causing the server to bog down. Based on suggestions from google's forum, I found some code that basically sent headers that told the googlebots that the page was not new. This code didn't work for me at the time, because I had output_buffering turned ON in my php.ini file. This apparently caused the "304 Not Modified" headers to be overwritten by PHP's default header creation.
Well, it's been awhile since I've worked on this dilemma. But, recently, I turned output_buffering OFF, and the code does actually work. However, I'm having one problem that I can't solve. If I try to start a session after this function is called, I get an error warning that the header has already been sent and it can't do that. It's just a warning, and doesn't seem to cause problems with the page itself. But, I don't like having my error log fill with these warnings. So, I can't just let it be.
Code: Select all
// $LastMod_UnixTS is a timestamp of the last modification of the page
function check_lastmod_header($LastMod_UnixTS)
{
ob_start();
$MTime = $LastMod_UnixTS - date("Z");
$GMT_MTime = date('D, d M Y H:i:s', $MTime).' GMT';
$ETag = '"'.md5($GMT_MTime).'"';
$INM = isset($_SERVER['HTTP_IF_NONE_MATCH'])? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : NULL;
$IMS = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : NULL;
if( ($INM && $INM == $ETag) || ($IMS && $IMS == $GMT_MTime) )
{
header('Status: Not Modified', true, 304);
ob_end_clean();
exit();
}
header("Last-Modified: $GMT_MTime");
header("ETag: $ETag");
ob_end_flush();
}If I start the session before this function is called, the function just doesn't work. I'm really close to just giving up. The only other solution I can think of, is to check if the visitor is a googlebot through HTTP_USER_AGENT and feed them a different response. I've read that this can upset the google gods, and hurt page rankings. How they would know is beyond me, but google certainly has the resources, so I wouldn't doubt that it's possible.
Thanks in advanced,
Swede