RES: RES: [PHP] RE: How to cache PHP on Apache
Hello! So, let me see if i understood: 1) Static content like Google´s logo(which i see every ten minutes :-) ) are cached with no problems. Actually, i´ve got that working. Does that always depend on the If-Modified-Since header? 2) Given that i send the proper header, could i receive as a response the 304 Not Modified for a dynamic content (GET something.php), just like the logo? If so, what would the proper header be? 3) Lets say that i got the php-response browser-cache working. Is it possible to store the cached response on my reverse proxy instead of the browser itself? Actually, thats what i would like to happen. Thank you for the help and best regards! Luanna -Mensagem original- De: Chris Shiflett [mailto:[EMAIL PROTECTED]] Enviada em: sexta-feira, 22 de novembro de 2002 18:40 Para: Luanna Silva; [EMAIL PROTECTED] Assunto: Re: RES: [PHP] RE: How to cache PHP on Apache Well, my explanation was not complete, because I wanted to make sure I was talking about the right thing. :-) One important thing I failed to mention is that caching applies to responses to GET and HEAD requests. If the response you showed us was a reply to a POST, it is not going to be cached. As far as the 304 responses are concerned, this depends in part on the Web browser. For example, if the browser sends a conditional GET request with an If-Modified-Since header (it has a date as a value), the Web server will make a decision. If the resource being requested has in fact been modified since the specified date, the entire resource is returned in a 200 OK response. If it has remained unchanged, a 304 Not Modified response is sent with no content, saving bandwidth. If you would like a good example to compare responses with, request an image from your Web server and notice the HTTP headers used. If you take a page such as Google as an example, your browser requests http://www.google/com first, receives the HTML from that, then notices the embedded image and requests http://www.google.com/images/logo.gif in a separate request. If you are like me and visit Google all the time, your browser has this image saved and rarely (usually only on holidays) gets anything but a 304 response from Google. So, for pages you make available via GET requests that you want to be cachable in the same way as Google's logo, you can start by mimicking what they do. Here is an example of the HTTP transactions required to see http://www.google.com/ (HTML and some headers edited for readability): -- GET / HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (...) Accept: text/xml, ... Accept-Language: en-us, en;q=0.50 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 Keep-Alive: 300 Cache-Control: max-age=0 -- HTTP/1.1 200 OK Content-Length: 9390 Server: GWS/2.0 Date: Fri, 22 Nov 2002 20:31:18 GMT Content-Type: text/html Cache-control: private html... -- GET /images/logo.gif HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (...) Accept-Language: en-us, en;q=0.50 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 Keep-Alive: 300 Accept: video/x-mng, ... Referer: http://www.google.com/ If-Modified-Since: Mon, 21 Oct 2002 02:32:25 GMT Cache-Control: max-age=0 -- HTTP/1.1 304 Not Modified Content-Length: 0 Server: GWS/2.0 Content-Type: text/html Date: Fri, 22 Nov 2002 20:31:19 GMT -- Hopefully that provides a little more information to get you going. Chris --- Luanna Silva [EMAIL PROTECTED] wrote: For the moment, i want to cache the HTTP Response. So, if i´m correct, the header that i sent to the list should do the job. I thought that, if the responses were cached, the access.log file would have 304 codes on the responses for php scripts. Is that correct? Well, if it is, that´s not happening. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: How to cache PHP on Apache
My header looks just like this: HTTP/1.0 200 OK Date: Sat, 16 Nov 2002 16:45:29 GMT Server: Apache/1.3.20 (Win32) PHP/4.0.6 Cache-Control: public, max-age=3600 Expires: Sat, 16 Nov 2002 17:45:29 GMT X-Powered-By: PHP/4.0.6 Content-Type: text/html And yes, we use sessions. So, setting session_cache_limiter() to public should solve my problem? The pragma header is what is missing? Instead of changing the code, could i use Apache´s mod_header to do the job? Thank you for the help! Luanna Do you use sessions? If so, try using session_cache_limiter() function. Otherwise connect directly to apache with telnet and see the headers yourself. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: How to cache PHP on Apache
Luanna, This response allows caching, but the cached response is only considered fresh for one hour (which might be appropriate for you), as is determined by both the Expires header and the max-age attribute of the Cache-Control header. The Pragma header is defined under HTTP/1.0 and is only used when backwards compatibility with HTTP/1.0 Web agents is required (meaning, Web agents that do not support HTTP/1.1). The absence of Pragma will not restrict caching in any way, however, even with an HTTP/1.0 cache. You can use PHP's header() function to manipulate headers. One thing I am not clear on is whether this type of caching is what you were originally inquiring about. The HTTP headers specify what restrictions are placed on the ability for a caching system to cache this HTTP response. It has nothing to do with caching the PHP script in any way on the server. If that latter sounds more like what you are interested in, there are several products that can help with this also. One is Zend Cache. Chris --- Luanna Silva [EMAIL PROTECTED] wrote: My header looks just like this: HTTP/1.0 200 OK Date: Sat, 16 Nov 2002 16:45:29 GMT Server: Apache/1.3.20 (Win32) PHP/4.0.6 Cache-Control: public, max-age=3600 Expires: Sat, 16 Nov 2002 17:45:29 GMT X-Powered-By: PHP/4.0.6 Content-Type: text/html And yes, we use sessions. So, setting session_cache_limiter() to public should solve my problem? The pragma header is what is missing? Instead of changing the code, could i use Apache´s mod_header to do the job? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RES: [PHP] RE: How to cache PHP on Apache
Chris, your explanation was just what i needed to really understand my problem :-) For the moment, i want to cache the HTTP Response. So, if i´m correct, the header that i sent to the list should do the job. I have: Apache Web Server 1.3.x A Reverse Proxy The client(IE 5.00) I thought that, if the responses were cached, the access.log file would have 304 codes on the responses for php scripts. Is that correct? Well, if it is, that´s not happening. If its not, i´m pretty lost :-) Thank you for the explanation! Luanna -Mensagem original- De: Chris Shiflett [mailto:[EMAIL PROTECTED]] Enviada em: sexta-feira, 22 de novembro de 2002 17:32 Para: Luanna Silva; [EMAIL PROTECTED] Assunto: Re: [PHP] RE: How to cache PHP on Apache Luanna, This response allows caching, but the cached response is only considered fresh for one hour (which might be appropriate for you), as is determined by both the Expires header and the max-age attribute of the Cache-Control header. The Pragma header is defined under HTTP/1.0 and is only used when backwards compatibility with HTTP/1.0 Web agents is required (meaning, Web agents that do not support HTTP/1.1). The absence of Pragma will not restrict caching in any way, however, even with an HTTP/1.0 cache. You can use PHP's header() function to manipulate headers. One thing I am not clear on is whether this type of caching is what you were originally inquiring about. The HTTP headers specify what restrictions are placed on the ability for a caching system to cache this HTTP response. It has nothing to do with caching the PHP script in any way on the server. If that latter sounds more like what you are interested in, there are several products that can help with this also. One is Zend Cache. Chris --- Luanna Silva [EMAIL PROTECTED] wrote: My header looks just like this: HTTP/1.0 200 OK Date: Sat, 16 Nov 2002 16:45:29 GMT Server: Apache/1.3.20 (Win32) PHP/4.0.6 Cache-Control: public, max-age=3600 Expires: Sat, 16 Nov 2002 17:45:29 GMT X-Powered-By: PHP/4.0.6 Content-Type: text/html And yes, we use sessions. So, setting session_cache_limiter() to public should solve my problem? The pragma header is what is missing? Instead of changing the code, could i use Apache´s mod_header to do the job? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] RE: How to cache PHP on Apache
Well, my explanation was not complete, because I wanted to make sure I was talking about the right thing. :-) One important thing I failed to mention is that caching applies to responses to GET and HEAD requests. If the response you showed us was a reply to a POST, it is not going to be cached. As far as the 304 responses are concerned, this depends in part on the Web browser. For example, if the browser sends a conditional GET request with an If-Modified-Since header (it has a date as a value), the Web server will make a decision. If the resource being requested has in fact been modified since the specified date, the entire resource is returned in a 200 OK response. If it has remained unchanged, a 304 Not Modified response is sent with no content, saving bandwidth. If you would like a good example to compare responses with, request an image from your Web server and notice the HTTP headers used. If you take a page such as Google as an example, your browser requests http://www.google/com first, receives the HTML from that, then notices the embedded image and requests http://www.google.com/images/logo.gif in a separate request. If you are like me and visit Google all the time, your browser has this image saved and rarely (usually only on holidays) gets anything but a 304 response from Google. So, for pages you make available via GET requests that you want to be cachable in the same way as Google's logo, you can start by mimicking what they do. Here is an example of the HTTP transactions required to see http://www.google.com/ (HTML and some headers edited for readability): -- GET / HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (...) Accept: text/xml, ... Accept-Language: en-us, en;q=0.50 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 Keep-Alive: 300 Cache-Control: max-age=0 -- HTTP/1.1 200 OK Content-Length: 9390 Server: GWS/2.0 Date: Fri, 22 Nov 2002 20:31:18 GMT Content-Type: text/html Cache-control: private html... -- GET /images/logo.gif HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (...) Accept-Language: en-us, en;q=0.50 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 Keep-Alive: 300 Accept: video/x-mng, ... Referer: http://www.google.com/ If-Modified-Since: Mon, 21 Oct 2002 02:32:25 GMT Cache-Control: max-age=0 -- HTTP/1.1 304 Not Modified Content-Length: 0 Server: GWS/2.0 Content-Type: text/html Date: Fri, 22 Nov 2002 20:31:19 GMT -- Hopefully that provides a little more information to get you going. Chris --- Luanna Silva [EMAIL PROTECTED] wrote: For the moment, i want to cache the HTTP Response. So, if i´m correct, the header that i sent to the list should do the job. I thought that, if the responses were cached, the access.log file would have 304 codes on the responses for php scripts. Is that correct? Well, if it is, that´s not happening. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: How to cache PHP on Apache
My header looks just like this: HTTP/1.0 200 OK Date: Sat, 16 Nov 2002 16:45:29 GMT Server: Apache/1.3.20 (Win32) PHP/4.0.6 Cache-Control: max-age=3600 Expires: Sat, 16 Nov 2002 17:45:29 GMT X-Powered-By: PHP/4.0.6 Content-Type: text/html And yes, we use sessions. So, setting session_cache_limiter() to public should solve my problem? The pragma header is what is missing? Instead of changing the code, could i use Apache´s mod_header to do the job? Thank you for the help! Luanna Do you use sessions? If so, try using session_cache_limiter() function. Otherwise connect directly to apache with telnet and see the headers yourself. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php