#native_company# #native_desc#

Making PHP Applications Cache-Friendly Page 2

By Klaus A. Brunner
on November 16, 2001

Making PHP Applications Cache-Friendly

One approach to minimising redundant transmission of data is the
use of Last-Modified and If-Modified-Since headers as defined in HTTP/1.1.
In this scheme, each object returned by the webserver carries a date
of last modification (a.k.a. “validator”). A user agent or proxy
cache can store this value and, upon the next reload of the same
object, issue a conditional GET query with the Last-Modified-Since
header set. The webserver will then use this header to decide
whether the client’s copy of the object is still “fresh” (as recent
as the data on the server) or “stale” (older than the data on the
server). If it is fresh, there is no need to send the object again,
so the server responds with a brief “304 Not Modified” message
Modern webservers and user agents (e.g., Apache/1.3,
Netscape Navigator 4.x and above, Internet Explorer) fully support
this technique. Apache automatically handles If-Modified-Since
requests for all static objects by default.
In the case of dynamic content as generated by PHP, we have to
take care of these things manually. We need to return a meaningful
Last-Modified header and handle If-Modified-Since requests so that
the user agent gets fresh data if and only if necessary. For
Phorum, this means that we have to keep track of database updates.
If the database has not changed since the client’s last request, we
can simply return 304 without bothering the DBMS at all.