PHP is a scripting language most often used to create Web applications.
It is easy to learn and produces visible results quickly. However, because PHP is interpreted,
PHP code is parsed and translated to bytecodes every time it executes. A bytecode cache
eliminates that rework, making PHP applications faster.
Much like other scripting languages used for Web applications, including Perl, Python, and Ruby,
PHP code is parsed, translated to bytecodes (primitive instructions - similar to assembly language --
that the PHP engine executes directly), and executed each and every time an HTTP request summons it.
For negligible and low demand, your server executes this complex rendering process seemingly
instantly. But as the number of pages served increases, interpretation -- in essence, rework -- can
tax the system. In some cases, the "compilation" of your PHP code can far exceed the time required
to execute the code. Hence, as demand grows, you can readily become a victim of your own success,
as serving more dynamically interpreted, dynamically generated pages requires more and more
One effective way to reduce the number of cpu cycles required to deliver a particular web page is
simply to reduce the amount of rework required to run your PHP application. Certainly, there is
no need to translate the same PHP code each time. After your PHP code has been translated into
bytecodes, it can be saved and reused again and again -- until the original code is modified.
Indeed, caching -- saving and reusing the intermediate PHP code, the bytecodes -- is the idea
behind several PHP accelerators, including the open source Alternative PHP Cache (APC), Turck
MMCache for PHP, XCache, eAccelerator, and the commercial Zend Optimizer. There is no change
to the existing installation of Apache and PHP.
This section of the condensed guide discusses the open source package Alternative PHP Cache (APC).
It is a free and open bytecode cache for PHP. It was conceived of to provide a free, open, and
robust framework for caching and optimizing PHP intermediate code to increase your server performance.
This section discusses in detais the following topics.
Build and install APC as a PHP extension. If you are not familiar with building a package
from source on Linux platform, or just want to skip the build step, this condensed guide supplies
the pre-built APC versions for Fedora, Centos, FreeBSD, and Ubuntu platforms.
Fine tuning the cache with run-time configuration parameters.
Disable and enable the cache.
How to compare results with and without caching using apache web server's benchmarking tools.