Caching Libraries and Opcode-Caches in php - An Overview

Flattr this
Tweet this: Caching Libraries and Opcode-Caches in php - An Overview
Dent this: Caching Libraries and Opcode-Caches in php - An Overview
Datum: 07.01.2010 02:33:01

Caching data is an important part in todays Web-Application, it can boost the performance, save time and resources or can be necessary because of limited or slow calls to external apis and services.

Things you can cache are for example database-querys, api-calls, generated data (html, images, .... ), return-values of methods and a lot more things.

Here is an overview of classes you can use to cache all kinds of data. From PEAR over the Symfony Framework to the Zend Framework. With slow file or database-based backends and fast memory-based backends like APC, Memcached, eAccelerator or Redis. After the caching-classes is a list with opcode-caches, because some of them offer memory-based cache-backends.
 

PHP-Caching Classes

 

Class Features Frontends / Backends Version / License / PHP-Version Tutorials / Snippets
PEAR Cache
  • Different Frontends
  • Different Backends
Frontends:
  • Standard
  • Application
  • Output
  • OutputCompression
  • HTTP-Request
  • Function
  • Graphics
Backends:
1.5.5 (2008-10-07)

PHP License 2.02

PHP 4.3.0
PEAR Cache_Lite

Documentation
  • Different Frontends
Frontends:
  • Standard
  • File
  • Function
  • Output
Backends:
  • File
1.7.8 (2009-07-07)

LGPL

PHP 4.0.0

sfCache

sfCache-API-Description

  • Different Frontends
  • Different Backends
via Plugin: Tagging
Frontends:
  • Standard
  • Function
Backends:
via Plugin: Redis, Zend Server (Disk + SHM)
1.4 (2009-12-01) Symfony Framework
MIT License
PHP 5.2.4
 
Zend_Cache

Documentation
  • Tagging (some backends)
  • Different Frontends
  • Different Backends
Frontends:
  • Standard
  • Class
  • File
  • Function
  • Output
  • Page
Backends:

Additional Backends (not Part of the Zend Framework):
Redis
eAccelerator
Zend_Registry
1.9.6 (2009-11-23)

New BSD

PHP 5.2.4

Like on most things I go with the solution provided by my framework. Zend Cache offers me some nice frontends and backends, can be directly used on many components of the Zend Framework (Zend_Locale, Zend_Translate, Zend_Db_Table_Abstract, Zend_Paginator and Zend_Feed_Reader) which offers direct support for caches and it is expandable by offering an interface for your own custom frontends or backends.

 

Opcode/Bytecode Caches

Opcode-caches are PHP-extensions which save the opcode generated by the compiler, so that for the next call to the file the PHP-Interpreter does not need to compile the PHP-code again into opcodes, it can directly be executed. When using frameworks or libraries with many files, using an opcode cache can really boost the performance. Most opcode-caches include access to the allocated memory which allows using them for caching data directly in the memory too, which is really fast.

Cache Description Version Systems and PHP-Versions
APC Probably the best known opcode-cache for PHP, will be part of the PHP-core in PHP6 3.0.19 (stable) (php 4 + 5)
3.1.3p1 (beta) (php 5, 5.3)
PHP 4, 5, 5.3 (beta)
XCache XCache is developed by the lighttpd-Team 1.3 PHP 4, 5, 5.3
eAccelerator Based on Turck MMCache 0.9.5.3 PHP 4, 5, 5.3
Windows Cache Extension for PHP Windows/IIS only opcode-Cache 1.0 Windows + IIS only PHP 5.2 / 5.3 x86 (32bit)
Zend Optimizer+ Zend's Optimizer included in their products like Zend Platform and Zend Server 3.3 PHP 4, 5

Not in the List because they are out-dated or don't support PHP 5 or newer: ionCube PHP Accelerator, Turck MMCache

I use APC as opcode-cache, like XCache it is in the Debian/Ubuntu-repository und easily installable via apt-get:

apt-get install php-apc
apt-get install php5-xcache

And since APC is Part of PECL it is easily installable via pecl:

pecl install apc

If you want to know which one is the best (speed/stability): test it yourself!
For the benchmark-loving people here are some links:

And some informations and slides on caching

Did I forget something ? Any misspelling ? Know another opcode-cache which should be mentioned ? Another caching-class ? Another tutorial/snippet for one of the caching-classes ?
Write a comment!


Trackbacks (0)

Trackbackurl: http://www.robo47.net/trackback/blogentry/192

Es sind keine Trackbacks vorhanden.


Kommentare (3)

Die Kommentare zu diesem Beitrag sind gesperrt.

You liked it ? Link it on your homepage or blog: