views:

440

answers:

3

What are the best resources or tutorials for caching in PHP 5? I'm looking for something that I could possibly build on my own. Zend Cache, APC, and similar utilities are also options, but I really want to steer away from full-fledged templating systems like Smarty, etc.

A: 

Zend Cache and APC are a different form of caching than what you're thinking about. These systems cache the bytecode generated after loading and "compiling" your scripts. In that regard, they only lift php to a standard that is common with almost any other scripting language.

The next, quite efficient, step is to enable query caching. In my experience with mySQL it has made quite a difference. Look at the mysql docs on how to enable it, it's one or two lines in my.cnf.

You're probably thinking more about caching HTML output. If your page is reasonably static, you could just use a reverse proxy such as squid. If the pages are dynamic, it gets harder. You can generate pages or fragments of pages, save them in the file system and expire them either after a certain amount of time or whenever the underlying data changes. I have been out of the php-loop for too long to know any existing packages, though.

MattW.
A: 

Not really a tutorial, but should help you. There are more PDFs from Flickr and LiveJournal floating around the web which I can't find right now.

http://sizzo.org/wp/wp-content/uploads/2007/11/facebook_performance_caching-dc.pdf

Gaurav
+1  A: 

Get APC and leverage the functions it adds to userland:

  • apc_fetch()
  • apc_store()

... for starters! :-)

Docs here: http://php.net/manual/en/ref.apc.php

The beauty of APC is, if you configure it, it uses RAM to as store for your cache.

Many frameworks also wrap around APC, or implement their own file-based caches.

Examples:

I've used all of the above and can recommend them.

Till