Why aren't my php files caching locally?
July 4, 2007 6:22 AM   RSS feed for this thread Subscribe

Why aren't my php files caching locally?

I'm using:
$offset = 3600 * 24;
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header('Cache-Control: max-age='.$offset.', must-revalidate');
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $date_cache)." GMT");


None of my php files are being cached in the browser while the js and image files are all getting cached just fine.

I'm using a default install of WAMP5 to put PHP from Win2003.
posted by twine42 to computers & internet (6 comments total) 1 user marked this as a favorite
And a secondary question, is there anything better than firebug? Its net reporting only gives you the time from the first received byte to the last, ignoring time between the request and the response.
posted by twine42 at 6:24 AM on July 4, 2007


Well, firebug is accurately giving you the **runtime** of the script, which doesn't include lag while your request filters through the intertubes. And no, there's nothing better than firebug. ;) Firebug is the -bomb-.

If there's a querystring in your PHP script's address, it will likely not be cached by your browser. Some browsers don't cache anything that ends in .php. There's another header setting somewhere that you can use to force caching, but I can't remember what it was and I'm too lazy to google.
posted by SpecialK at 6:27 AM on July 4, 2007


Oh, I love firebug. I just wish it would give me more info! :)

The files in question don't have query strings but they do go through a mod rewrite.
posted by twine42 at 6:47 AM on July 4, 2007


You probably want to be checking $_SERVER['HTTP_IF_MODIFIED_SINCE'] and sending header("Status: 304 Not Modified"); appropriately.

You may also want to send a header("ETag: \"$some_identifier\"") if possible, and handle $_SERVER['HTTP_IF_NONE_MATCH'] similarly. Of course either way it shouldn't really be revalidating that often, but maybe some clients do so anyway. Your testing methodology will likely have an effect here.

Dropping must-revalidate might be a good idea if it's not the end of the world if the user doesn't get a validated response after max-age: "Servers SHOULD send the must-revalidate directive if and only if failure to revalidate a request on the entity could result in incorrect operation, such as a silently unexecuted financial transaction." -- the client should* still *try* to revalidate, but if, say, your server is down, it can theoretically just serve the stale cached version.

* Not an alternative to reading rfc2616. Slippery when wet. Beware of Leopard.
posted by Freaky at 7:53 AM on July 4, 2007


Stupid question: Is your server set to use GMT for time()?
posted by SpecialK at 9:04 AM on July 4, 2007


On a tangent.. the best tool I have found to-date for debugging this kind of thing is Paros. It is a debugging proxy that logs absolutely everything, lets you manipulate any part of any query in-transit, and so on.
posted by TravellingDen at 11:33 AM on July 4, 2007


« Older I no longer get "properti...   |   Netherlands: Recommendations f... Newer »
This thread is closed to new comments.


Related Questions
Do burglars read AskMeFi? July 21, 2008
Use up to ___ MB of space for the cache May 10, 2008
How is Facebook doing its queries? February 4, 2008
Is it possible to write a program that uses only... November 30, 2006
I want to explore! July 1, 2006