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 |
|
Frontends:
|
1.5.5 (2008-10-07) PHP License 2.02 PHP 4.3.0 |
|
|
PEAR Cache_Lite Documentation |
|
Frontends:
|
1.7.8 (2009-07-07) LGPL PHP 4.0.0 |
|
|
sfCache |
|
Frontends:
|
1.4 (2009-12-01) Symfony Framework MIT License PHP 5.2.4 |
|
|
Zend_Cache Documentation |
|
Frontends:
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:
- Benchmarking Drupal with PHP op-code caches: APC, eAccelerator and XCache compared
- PHP Bytecode Cacher Review (Old is from 2006)
And some informations and slides on caching
- PHP Perfomance Series: Caching Techniques by Mike Willbanks
- Caching Data For Performance by Dave Ross
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/192Es sind keine Trackbacks vorhanden.
You liked it ? Link it on your homepage or blog:



Benjamin Steininger ist Webentwickler auf der Suche nach einem neuen Job und
photographiert sehr gerne. Er beschäftigt sich viel mit dem Internet, PHP, Symfony, Testing und hat einen
Kommentare (3)
Wie findest du das?
Cachen mit DBM Dateien - http://krsteski.de/php-tricks-und-tipps/cachen-mit-dbm-dateien.htmlMuss ich mir bei gelegenheit mal anschauen, ob sich das für Systeme wo man keine speicher-basierten systeme hat, anstatt z.b. sqlite oder gleich einem datei-basierten System lohnt.
Habe es mal endlich geschafft das Ganze auf GitHub hoch zu laden.
https://github.com/gjerokrsteski/php-dba-cache
Die Kommentare zu diesem Beitrag sind gesperrt.