Making PHP Applications Cache-Friendly
db/postgresql.php: (virtually identical for other databases)
<?
class query {
var $result;
var $row;
var $curr_row;
function query(&$db, $query="") {
// Constructor of the query object.
// executes the query, notifies the db object of the query result to clean
// up later
GLOBAL $modification_file;
if($query!=""){
if (!empty($this->result)) {
$this->free(); // query not called as constructor therefore there may
// be something to clean up.
}
$this->result=@pg_Exec($db->connect_id, $query);
// catch database-altering SQL statements
if(isset($modification_file) && eregi("^(insert|update|alter|delete)", $query))
touch($modification_file);
$db->addquery($this->result);
$this->curr_row=0;
}
}
?>
Bottom Line
If you have an efficient way of tracking the freshness of your
data, implementing proper Last-Modified/If-Modified-Since behaviour
for PHP applications is very simple. It has clear benefits for both
server and client side, and usually no drawbacks. Considering that, it is
surprising how rarely it seems to be used by PHP authors.
data, implementing proper Last-Modified/If-Modified-Since behaviour
for PHP applications is very simple. It has clear benefits for both
server and client side, and usually no drawbacks. Considering that, it is
surprising how rarely it seems to be used by PHP authors.
Of course, this isn’t all there is to creating cache-friendly PHP scripts. For further information, check Mark Nottingham’s Caching Tutorial for Web Authors and Webmasters.
–Klaus A. Brunner