Forum Moderators: coopster

Message Too Old, No Replies

Header( ) and Cache Problem

Is there a simple set up to insure page caching?

         

bumpaw

7:20 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



I am just made aware of the effect of Header( )and page caching for PHP pages. It seems that my pages are not being cached because I was furnishing no information in a header. A couple of hours searching led me mostly to folks that want to prevent caching in certain cases. It all seems rather confusing, and I'm hoping that out there somewhere is a generic Header( )set up that will allow my CSS file to be cached in the users browser.

jamie

7:47 pm on Apr 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi bumpaw

start here with this post on if modified since [webmasterworld.com]

and read web-caching.com - a very useful resource.

we send the last modified date of the script with the line:

header("Last-Modified: $last_modified");

where $last_modified is in this format:
Thu, 8 Apr 2004 07:43:40 GMT

you can work out your last modified date for each script either using filemtime(), or if using dynamic content by comparing the filemtime() with the timestamp value of your databased data and send the most recent one as your last_modified header.

many sites don't bother, as depending on the complexity of your scripts and database calls, it can be more trouble than it is worth to calculate. see this post here on why so many php sites don't use last modified headers [webmasterworld.com]

you can use the header checker [searchengineworld.com] on this site to see if you are returning the last modified date correctly

imo if you are not using any databased data, then there is no excuse for not sending correct last mod headers ;-)

good luck

bumpaw

8:36 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



Hey Jamie,
Thanks for your quick response.
I had already visited [ircache.net...] before posting, and ran my site through their Cachability Checker. It seems from their extensive writings that I would need several headers one of which is Content-length.

jamie

4:42 pm on Apr 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



we send a last-modified header and an etag using a slightly modified version of this script [simon.incutio.com]

we don't bother with content length and have never found any problems with caching. you could send content length like this (if using output buffering)

$content_length = ob_get_length();
header("Content-length: $content_length");

cheers