Boosting Up PHP Performance with Alternative PHP Cache (APC)

“Every single server has it [APC] at Yahoo, and it handles billions of requests per day” Said Rasmus Lerdorf, the creator of PHP, at the php|works conference.

Parsing and compiling speed can be significantly boosted with the use of an opcode cache.

In PHP, as with most scripting languages, code is parsed from human-readable to machine-readable instruction. The machine-readable script is known in PHP as opcodes.

An opcode cache stores or caches the compiled code in shared memory so that the code compilation for similar operations only needs to happen once.

PHP 6, which is still in development, will have opcode cache built in by default.

For current PHP 5 users, there are various opcode cache implementations that can be used, including the Alternative PHP Cache (APC), which is what Lerdorf recommended.

Installation (Linux):
APC is available via PECL Repositry, you can install it vie `pear install apc`, but it would fail if you compiled apache alone (didn’t install a binary package .deb or .rpm), so it could be a little bit tricky, I’m going to show you how to install it given that apache and php were compiled alone, and they are in there default locations

download it from http://pecl.php.net/get/APC-3.0.12p2.tgz

$ tar xzf APC-3.0.12p2.tgz
$ cd APC-3.0.12p2
$ phpize
$ ./configure –enable-apc-mmap=yes –with-apxs=’/usr/local/apache/bin/apxs’

you can replace /usr/local/apache/bin/apxs with your location to apxs e.g. /usr/local/apache2/bin/apxs if you installed apache2 in it’s default location
$ make
$ make install

After that you have to load it in php.ini
Be sure that extension_dir = “/usr/local/lib/php/extensions” or whatever your extentions folder is
add a line:
extension=no-debug-non-zts-20050922/apc.so
fix it according to the location of apc.so

try it out, it really Boosts Up your PHP applications performance

Leave a Reply

Your email address will not be published. Required fields are marked *