Forum Moderators: coopster
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?
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?