tags:

views:

394

answers:

7

I have read a few things here and there and about PHP being able to "cache" things. I'm not super familiar with the concept of caching from a computer science point of view. How does this work and where would I use it in a PHP website and/or application.

Thanks!

A: 

Have a look at Zend Cache

Silfverstrom
Be aware this is just a wrapper.
Itay Moav
A: 

Here is a good introductory article, by The UK Web Design Company, on how caching is done with php. There are products available that simplify this process a bit.

Matthew Vines
+4  A: 

You can cache:

  1. Query results
  2. The HTML output of a PHP script/request
  3. Cache variables
  4. Cache parts of a page.
  5. Cache the code itself (speeds up things, no need to do bytecode).

Each of those is a different subject with different methods.

Itay Moav
+2  A: 

"How does this work" >> well, if done properly

How to use cache ? Well, there are many types of solutions :

  • caching parts of web pages (or even full pages) ; you can take a look at PEAR Cache_Lite (there are things like this in probably every existing frameworks ; there is in Zend Framework, with many backends supported)
  • caching data (like objects, for instance) ; you can cache to files, to RAM (with APC for instance), to a caching server (like memcached, for instance)
    • that data can come from many sources ; generally, it'll be from database, or a call to a webservice, or stuff like that
    • that data will generally be something : often used, hard / long / costly to get
  • you can also (not specific to PHP, though) use a reverse proxy (like varnish, for example) as a frontend to your web server, to cache entire HTML pages

The subject is really vast : there is almost an infinite number of possibilities... But one thing to remember is : don't use caching "just to use caching" : caching, like anything else, can have drawbacks ; so use it if/when necessary...

Pascal MARTIN
+2  A: 

There are many questions on StackOverflow already about PHP and Caching. Perhaps if you were more clear in you question (right now it has poor grammar and sort of vaguely rambles), we could better answer you.

davr
A: 

Not exactly about php but, refering just to the caching of the html output, there are also templating systems like smarty capable to cache. I use it and I like how it works.

dam
A: 

Have a look at Pear Cache and Cache_Lite at http://pear.php.net

andreas