Forum Moderators: coopster

Message Too Old, No Replies

PHP caching

howto

         

huwnet

6:12 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



I have a php random avatar script. It seems to use more bandwidth than when there was just one image.

Can I send a header in the php script to tell the client to cache the image?

Thanks

inveni0

6:46 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



It should already do this. Special header information is required to tell the browser NOT to cache, so it should cache automatically.

Now, the structure of your randomization may differ. If each image is named the same, then it may replace itself each time, causing server to reload the image each time it changes.

huwnet

8:48 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



Maybe it is something that has started taking up bandwidth then.

The server headers are as follows, with cookie and URLS removed:


http://mysite.com/f/avatar.png

GET /f/avatar.png HTTP/1.1
Host: mysite.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0

HTTP/1.x 200 OK
Date: Sat, 25 Feb 2006 20:50:05 GMT
Server: Apache/1.3.34 (Unix) mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.2 FrontPage/5.0.2.2635 mod_ssl/2.8.25 OpenSSL/0.9.7a
Connection: close
Transfer-Encoding: chunked
Content-Type: image/gif
----------------------------------------------------------
http://mysite.com/f/avatar.png

GET /f/avatar.png HTTP/1.1
Host: mysite.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
Accept: image/png,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Date: Sat, 25 Feb 2006 20:50:05 GMT
Server: Apache/1.3.34 (Unix) mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.2 FrontPage/5.0.2.2635 mod_ssl/2.8.25 OpenSSL/0.9.7a
Connection: close
Transfer-Encoding: chunked
Content-Type: image/gif
----------------------------------------------------------