PHP Caching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gskidmor
Forum Newbie
Posts: 3
Joined: Tue Feb 19, 2008 2:32 pm

PHP Caching

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Caching

Post 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
(#10850)
gskidmor
Forum Newbie
Posts: 3
Joined: Tue Feb 19, 2008 2:32 pm

Re: PHP Caching

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Caching

Post by Christopher »

The header() function sets the HTTP headers that are sent before the HTML.
(#10850)
gskidmor
Forum Newbie
Posts: 3
Joined: Tue Feb 19, 2008 2:32 pm

Re: PHP Caching

Post 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.
Post Reply