Forum Moderators: coopster

Message Too Old, No Replies

Headers

a sanity check please

         

grandpa

11:27 pm on Jun 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I got headed down this road of server headers, and I believe that I'm doing everything right to send the correct response codes for my pages.

I've created dynamic pages that, when the database content gets updated for a page, I'll execute a touch(myfile.php) on the appropriate php page.

Then, in the php page I have this code

<?php
$filename = 'myfile.php';
$if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
$mtime = filemtime($filename);
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ($if_modified_since == $gmdate_mod) {
header("HTTP/1.0 304 Not Modified");
// added cache-control
header("Cache-Control: max-age header");
exit();
}
else {
header("Last-Modified: $gmdate_mod");
}
?>

The final bit is in my .htaccess, where I have a Rule

RewriteRule ^myfile.html$ http://www.example.com/myfile.php [L]

This seems to be working... when I check my logs I find a 200 Response Code after touching the php file, and a 304 Response Code if nothing has been changed.

Did I miss anything really important here? What I'm trying to do is have the page cached unless something has changed in the database. And, for reasons not yet totally clear, it seems that having a cached version of the dynamic page will reduce the load on the database?

grandpa

10:00 pm on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*cough*

What I'm trying to do is have the page cached unless something has changed in the database. And, for reasons not yet totally clear, it seems that having a cached version of the dynamic page will reduce the load on the database?

Ignoring all of the above, this is what I'd really like to know

Did I miss anything really important here?

jatar_k

10:12 pm on Jun 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ahem.. ;)

not that I can think of off the top of my head

grandpa

10:45 pm on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks.

It's going to take a while to just read thru RFC2616, probably longer to understand the contents, particularly Chapters 13 & 14. Life seems much easier when it's handled automatically...

jatar_k

10:56 pm on Jun 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> easier when it's handled automatically...

I agree, cron jobs pretty much take care of my life these days. ;)