Re: Re: how to retrieve pictures from postgreSQL DB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alain Roger wrote:
> Sorry Colin,
> 
> but what do you mean by "adding some cache related headers" ?
> What is the idea behind that ?

Well, PHP is a dynamic language and as such it tells web browsers
(Firefox, Safari etc.) "DO NOT CACHE THIS PAGE, I MAY GENERATE IT
DIFFERENTLY NEXT TIME!!!".

So that means that when a browser downloads a page, and then the user
goes back to that page later (e.g. by hitting "back" etc.) then the user
will have to ask the server and it will supply an updated version of the
page.

The same thing applies for images, but due to the sizes involved this
may be very ugly for users and result in quite slow
performance/rendering of your pages, not to mention increased bandwidth etc.

So you'll almost certainly want some URL rewriting to get neat URLs and
you'll definitely want to put some header() calls with cache control
headers.

Just search for "cache control headers" and you'll find out more.


Something like:

    header('Expires: '.gmdate('D, d M Y H:i:s', time()+CACHE_TIME).' GMT');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_mod . ' GMT');
    header('Cache-Control: max-age='.CACHE_TIME.', public');


But you'll also want to check to see if the header "If-Modified-Since"
is used such that you can return a very simple header in response.

e.g.

      $headers = apache_request_headers();
      if (isset($headers['If-Modified-Since']))
      {
        $if_modified_since = preg_replace('/;.*$/', '',
$headers['If-Modified-Since']);
        if ('' != $if_modified_since)
        {
          if (time() - strtotime($if_modified_since) < CACHE_TIME)
          {
            header('HTTP/1.1 304 Not Modified');
            exit;
          }
        }
      }

The above prevents you having to supply any data as the browser is just
asking you if you've got a newer version than the one it has, and quite
often you can reply say, nah, your one is fine!

HTHs

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux