PDA

View Full Version : Best Caching Method?


Joseph Witchard
06-07-2009, 09:14 PM
I've been reviewing caching methods with .htaccess on Apache, and I'm a little confused. Some tutorials use mod_headers, while some use mod_expires, while some use both. Are any of them better than the other? And is this the same as caching by HTTP headers?

eak
06-08-2009, 05:00 PM
Those two mods have different purposes, but both can achieve the same result.

http://httpd.apache.org/docs/2.0/mod/mod_headers.html
http://httpd.apache.org/docs/2.0/mod/mod_expires.html

I like the simplicity of mod_expires:
ExpiresDefault "access plus 30 days"

But with mod_headers, you have greater control over what http headers are sent.


These two mods control the headers that browsers look at for client side caching.
If you want server side caching, look into memcache (http://www.google.com/search?q=apache+memcache)

Joseph Witchard
06-11-2009, 05:12 AM
Is this the same as using http headers? Same syntax and everything?

eak
06-11-2009, 04:09 PM
Is what the same as using http headers?

Joseph Witchard
06-11-2009, 11:23 PM
Is what the same as using http headers?

mod_headers and mod_expires.

eak
06-12-2009, 04:34 PM
Yes, both of those mods will edit/append http headers when Apache sends a document.

Joseph Witchard
06-13-2009, 04:49 AM
All right. Since they have "mod" in their names, am I right in assuming that they're considered part of Apache Mod_Rewrite?

eak
06-15-2009, 04:01 PM
No, they are not associated with that module.
Many Apache modules use that naming convention to indicate that it is a module.

Joseph Witchard
06-15-2009, 11:04 PM
Ah, okay.

Is there really a need for server-side caching if I do it on the client side? Also, is there a certain mime type for PHP files?

eak
06-16-2009, 05:45 PM
Yes, server side caching has its benefits, especially for large sites.
For example, you can use memcache to store your query results in memory.
There are also modules for caching PHP opcode (APC for instance).
I read somewhere that an opcode cache will be included in PHP6.


I think the php mimetype is application/x-httpd-php. What do you need that for?
I have never need that since I primarily use php to send text/html or application/xhtml+xml.

Joseph Witchard
06-17-2009, 07:31 AM
Yes, server side caching has its benefits, especially for large sites.
For example, you can use memcache to store your query results in memory.
There are also modules for caching PHP opcode (APC for instance).
I read somewhere that an opcode cache will be included in PHP6.


I think the php mimetype is application/x-httpd-php. What do you need that for?
I have never need that since I primarily use php to send text/html or application/xhtml+xml.

I don't need it. I found out that text/html works fine; I just assumed that I would need it if my files ended with .php, but I guess that's not the case. When would be a good time to use the PHP mime type, though? Could you give an example?

eak
06-17-2009, 04:06 PM
One place I can think of is phps files and Apache.
AddType application/x-httpd-php-source phps

That will show syntax highlighted source code for phps files.

Using the php mime type, instead of text/html, may allow someone to download your php files. There are other ways to force downloads though (application/octet-stream, for example).