Page 1 of 1

PHP Caching

Posted: Tue Feb 19, 2008 2:39 pm
by gskidmor
I think this one is a two parter, but maybe not...

I've created a site that I tried to control the caching scheme through html (I don't use the php header(...) function). It looks roughly like this:

Code: Select all

 
<html>
<head>
<meta http-equiv="Cache-Control" content="max-age=86400" />
</head>
<body>
<? include( "getSomeDataFromDB.php" ); ?>
</body>
</html>
 
This appears to work for me at home, but at work (I'm behind a proxy) if I visit the site, certain pages expire much quicker (read: immediately) than the Cache-control specifies. These pages are POST pages.

Do I need to send the Cache-control directive through a call to the php function head() or do I need something else?

Thanks
Jerry

PS - the page is here: http://www.divethegreatlakes.com

Re: PHP Caching

Posted: Tue Feb 19, 2008 3:16 pm
by Christopher
Look at the manual page for header() first and read the comments. Let us know what you found, because others will probably be interested.

http://us3.php.net/header

And of course:

http://www.google.com/search?hl=en&q=ph ... gle+Search

Re: PHP Caching

Posted: Tue Feb 19, 2008 4:50 pm
by gskidmor
I had read through some of those pages prior to posting here, but still had questions. I did read some more and I was just experimenting with following:

Code: Select all

header("Cache-control:private, max-age=3600");
It doesn't insert any text/directives into the page, so how would the client's browse know to cache the page locally? And, how would the above line differ any from the static cache-control directive I had within the <head> tags of my original post?

Thanks
Jerry

Re: PHP Caching

Posted: Tue Feb 19, 2008 4:56 pm
by Christopher
The header() function sets the HTTP headers that are sent before the HTML.

Re: PHP Caching

Posted: Wed Feb 20, 2008 5:51 am
by gskidmor
I just checked this morning since I'm at work and it is still expiring. I send this line:

Code: Select all

header("Cache-control:private, max-age=3600");
I think there's something I'm just not understanding here.