Recipe 21.6. Using an Accelerator


21.6.1. Problem

You want to increase performance of your PHP applications.

21.6.2. Solution

Install a code-caching PHP accelerator to allow PHP to avoid compiling scripts into opcodes on each request.

21.6.3. Discussion

PHP code accelerators do the bulk of their magic transparently by storing compiled versions of PHP scripts on disk or in shared memory in order to skip the compiling step with each request.

When the PHP interpreter is told to run a particular program, it reads the source code of the program and compiles it into a compact internal representation. Then, it executes the instructions in that compiled representation. When it's done executing the script, the interpreter throws away the compiled representation.

An accelerator, by contrast, keeps the compiled instructions around. The next time the PHP interpreter gets a request to run the same program, the accelerator steps in and checks whether it's saved a compiled version of that program. If so, it tells the PHP interpreter to skip recompilation and just execute the already compiled version. An accelerator can be configured to update its compiled representations based on different criteria, such as whenever the original program changes or only when you explicitly tell it to.

The three most popular freely available PHP accelerators are the Alternative PHP Cache (APC), eAccelerator, and the ionCube PHP Accelerator (PHPA). The freely available Zend Optimizer can also help with small performance increases by transparently correcting common but inefficient coding practices. However, the Zend Optimizer is not an accelerator.

There are a few important distinctions between the freely available accelerators that may influence your choice on which one to use. Issues such as Windows support, PHP 5 compatibility, Zend Optimizer compatibility, and functionality that goes beyond code caching may all be important in your decision on which accelerator to use. Benchmarks have shown that all the accelerators improve performance a roughly equivalent amount, so the deciding factor will most likely be one of these other issues.

APC and eAccelerator are open source projects with ongoing development. (eAccelerator is a fork of the Turck MMCache project, on which development has stopped.) The ionCube Accelerator is a commercial product. Developer responsiveness to bugs should also factor into your decision on which accelerator to use. Make sure to check the current status of open bugs with each accelerator and how those issues may affect you based on the version of PHP you're using, and the type of code (OOP versus procedural) your applications are based on.

Finally, it is important to recognize that accelerator compatibility often lags behind new PHP releases. If running the latest and greatest version of PHP is important to you, you may find that you are rarely able to take advantage of the benefits that an accelerator can provide.

21.6.4. See Also

The APC web site at http://pecl.php.net/package/apc; the eAccelerator web site at http://www.eaccelerator.net/; the PHPA web site at http://www.php-accelerator.co.uk/ .




PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net