Forum Moderators: coopster

Message Too Old, No Replies

php/mysql cache?

         

bobnew32

3:45 am on May 9, 2003 (gmt 0)

10+ Year Member



Well my entire site is based upon php and mysql, and most of it updates regularly. The problem is that once you go to a page you have already been to, you must hit the refresh button or else you will get the same content. This is really frustrating b/c I add new stuff/features to my site all the time and a person new to the site may not know to hit refresh. Can anyone offer a solution? (also I'm wondering if it is anything to do with the code in my head part of the page and btw I write my pages by hand in dreamweaver).

dmorison

4:32 am on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Include the following in the <head> section of your pages:

<meta http-equiv='Pragma' content='no-cache'>
<meta http-equiv='Expires' content='Mon, 01 Jan 1990 00:00:01 GMT'>

This should help.

bobnew32

10:33 am on May 9, 2003 (gmt 0)

10+ Year Member



Hmmmm, I understand the coding, but is it necessary to have the date be 1990? Thx for the code tho!

ruserious

10:40 am on May 9, 2003 (gmt 0)

10+ Year Member



Instead of putting it into the html, you can also send the appropiate headers:

header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

Remember that you must use these header() outputs before you output anything to the browser. Even a blank/space before the header will cause an error (because your webserver then will already have sent some the header).

Or if you have some more time:
[zend.com...]

dmorison

2:11 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmmm, I understand the coding, but is it necessary to have the date be 1990?

I guess it covers you in the case of the clock on your server running fast, or the users clock running slow...

:)

bobnew32

7:31 pm on May 9, 2003 (gmt 0)

10+ Year Member



One extra comment, would this also also not cache images? I would be having images change but I would like them to be cached, does that code allow that?

daisho

1:49 am on May 10, 2003 (gmt 0)

10+ Year Member



ruserious solution is more reliable as it doesn't rely on parsing the HTML but uses HTTP headers. This is what I use when I want to break caches. It will work for Images, HTML or any other type of content.

daisho.

bobnew32

4:35 pm on May 10, 2003 (gmt 0)

10+ Year Member



But is there a way to not cache images? That would greatly speed up the loading time of the pages.

daisho

6:12 pm on May 10, 2003 (gmt 0)

10+ Year Member



how do you figure not caching images will speed up page loading?

bobnew32

8:46 pm on May 10, 2003 (gmt 0)

10+ Year Member



Lol, i'm sorry, when I did my last post I was a little sleepy. I meant to say is there a way to cache images and not text/other stuff? Thats what other major sites do right, cache images and not cache other dynamic text?

daisho

11:15 pm on May 10, 2003 (gmt 0)

10+ Year Member



no problem :) Are these images in a database or are they just static images located in a directory? Also are you on Windows or Linux using IIS or Apache?

daisho.

bobnew32

1:46 am on May 11, 2003 (gmt 0)

10+ Year Member



Well, the image url is in a database, and I know its apache, but I'm not sure about linux for windows, but i'd say linux.

ruserious

9:01 pm on May 13, 2003 (gmt 0)

10+ Year Member



Images are fetched in their own HTTP-Request. So when someones opens index.php which has 3 img-tags (<a src="...), than you have 4 requests to your webserver

GET /
GET /img1.gif
GET /img2.gif
GET /img3.gif

And each one returns their own HTTP-repsonse headers.

img that are static, i.e. lie around somewhere on your webspace, usually get served normally by your webserver with the appropiate headers so they will get cached (unless the user overrides a settting in his browser-programm).
If you were to create images on the fly with a script, you would have to make sure your php-script sends the right headers. See my link above on how to do that.

Since in your case you only get the links to the images from the database I assume your files are simply stored on your webserver somewhere below the documentroot. So you don't have to do anything. ;)

daisho

2:02 am on May 14, 2003 (gmt 0)

10+ Year Member



I would put images in their own "images" directory. Then there is an apache directive that you can use to set cachability. I believe you can also do this based on file extension (or regex).

Check apache dot org for details on what the extact parameters and settings are. This will make your images _more_ cacheble.

daisho.