Out of curiosity I decided to invest a few hours and tested three PHP products that offer Bytecode (Opcode) Caching.
There are five products available, of which I tested three:
- Zend Platform
- APC (APC GUI)
- ionCube Encoder
- PHP Accelerator not tested, does not support PHP 5.x
Since I am a lazy turd, I used my development box for the benchmark, which runs WinXP Pro (SP2), Apache 2.0.59 and PHP 5.1.2.
Installing and setting up either APC and XCache was easy enough. The Zend Platform gave me some headaches. It would not finish its installer, saying “Registering Node with the Zend Central”. After some trial and error (playing with the web server address - localhost, 192.168.1.10, 127.0.0.1), 127.0.0.1 and using “Express Installation” did the trick. Well, sort of. The weird message still doesn’t want to go away, but apparently everything works just fine. And very fine, how you will see soon.
But let me introduce the scripts used in the benchmark. First, a simple “Hello World!” script. Then the “Main”-tab of phpMyAdmin 220.127.116.11 and last but not least the homepage of a freshly installed MediaWiki 1.7.1. Since the latter two require a database, and thus a database server, here is what I currently use: MySQL 4.1.13, more or less out of the box. So nothing fancy here. PHP itself is equipped with two extensions, mbstring and mysqli. On top of that either APC, XCache, eAccelerator or ionCube. For the Zend Platform, the delivered Apache 2.0.50 and PHP 5.0.5 were used.
Each configuration was softly hammered with five tasks via ab:
- Execute helloworld.php 1000 times
- Execute phpMyAdmin/main.php 100 times
- Execute phpMyAdmin/main.php 1000 times
- Execute mediawiki-1.7.1/index.php/Main_Page 100 times
- Execute mediawiki-1.7.1/index.php/Main_Page 1000 times
The guys over at iPerSec did a similar benchmark. They added a timestamp change for the requested files to see how the cachers cope with that. Personally I believe that in a production environment such changes do not happen that often, so I skipped this suggestion.
OK, here the executive summary:
- Use APC or XCache. Both provide a performance gain of over 190%. APC may have an advantage because it belongs to PECL, a controlled set of offical extensions for PHP. XCache is relatively new, but sure worth a look.
- ionCube Encode is not a real opcode cacher. It is used to encode your PHP source to protect it from being read and altered. It offers to optimize the code while encoding it. Since the code needs to be decoded to run, ionCube fails and comes out even below standalone PHP wit just 94% of its performance.
- Zend Platform increases overall performance to 128%. Of course Zend Platform is much more than an opcode cache - it offers debugging, drilling into events and monitoring of all things PHP related. Tight integration with Zend Studio makes these two a very powerful development environment. There are evaluation versions available, to go ahead and find out for yourself. The even greater news: Zend Platform is free for developers!