#native_company# #native_desc#
#native_cta#

Making PHP Applications Cache-Friendly Page 4

By Klaus A. Brunner
on November 16, 2001

Making PHP Applications Cache-Friendly

db/postgresql.php: (virtually identical for other databases)

<?

class query {

 

  var 
$result;

  var 
$row;

  var 
$curr_row;

 

  function 
query(&amp;$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-&gt;result)) {

        
$this-&gt;free(); // query not called as constructor therefore there may

                       // be something to clean up.

      
}

      
$this-&gt;result=@pg_Exec($db-&gt;connect_id$query);

 

      
// catch database-altering SQL statements

      
if(isset($modification_file) &amp;&amperegi("^(insert|update|alter|delete)"$query))

         
touch($modification_file);

 

      
$db-&gt;addquery($this-&gt;result);

      
$this-&gt;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.
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

1
|
2
|
3
|
4