Today, most websites of any complexity incorporate PHP code in their HTML. PHP eAccelerator can help you improve the performance of your PHP scripts by up to 10 times by caching PHP scripts in their compiled state, reducing the overhead incurred by compiling the scripts every time a user requests them. The compiled scripts are stored in and executed from shared memory, though if a script is too big, PHP eAccelerator can store it on disk. PHP eAccelerator supports PHP5 and is lighter and faster than any other optimizer I have come across.
Installing PHP eAccelerator is easy. For CentOS or Red Hat, you can install its binary package from the Extra Packages for Enterprise Linux (EPEL) repository. If you don't already have the EPEL repository, its FAQ explains how to add it to your system. You can then install eAccelerator with the command yum install php-eaccelerator.
yum install php-eaccelerator
If PHP eAccelerator is not available in a binary package for your Linux distribution, you can build it from source. Download the PHP eAccelerator source and extract it using the command tar -xzvf master. Run phpize in the source directory, then run ./configure and make to compile it, and install it with make install. When the software is installed, you should see the new file eaccelerator.so in your PHP modules directory – usually /usr/lib64/php/modules/ for 64-bit servers.
tar -xzvf master
If you install PHP eAccelerator using yum, it creates the file eaccelerator.ini in your /etc/php.d/ directory, and you're ready to run. If you did a source install, append the following lines to your php.ini file:
; Name of the extension
; shared memory size in magabytes
; the directory to be used as disk cache
; "1" to enable the eaccelerator, 0 to disable it
; "1" to enable the code optimizer, 0 to disable it
; "1" to enable the php file modification checking, 0 to disable it
; "1" to enable the debug logging, 0 to disable it
; Determine which PHP files must be cached. You can give wild cards here.
; When eAccelerator fails to get shared memory for new script it removes all scripts which were not accessed at last "shm_ttl" seconds from shared memory.
; When eAccelerator fails to get shared memory for new script it tries to remove old script if the previous try was made more then "shm_prune_period" seconds ago.
; Enables or disables caching of compiled scripts on disk.
You can find a complete list of all the program's options with detailed explanations in the project's wiki.
Make sure that the directory you specified for eAccelerator's cache exists. If you have to create it, make sure it is writable by the user that runs your webserver – usually apache or nobody or www-data. To start eAccelerator, restart your web server, then verify that eAccelerator is really loaded by executing the command php -v . The last line in the output of that command should indicats that eAccelerator has been loaded and is ready for action.
If you want a more detailed check, you can run phpinfo() in a PHP script. To do that, create a file with the contents below and move it to your website:
Open the file on your site and you should see an entire section of details on eAccelerator.
PHP eAccelerator should make a noticeable difference in the performance of any busy PHP-based website. Many benchmarks suggest that it is the fastest of all the optimizers out there – but it's not your only option.
APC, the Alternative PHP Cache, provides another framework for caching and optimizing PHP intermediate code. It may not be as fast as PHP eAccelerator, and it has a larger memory footprint, but it is better maintained; it is developed by PHP project volunteers themselves, and has a better chance of long-term support.
If you use lighttpd as your web server, look at XCache PHP Optimizer, which is developed by one of lighttpd's core developers. The project generally puts out new releases of XCache quickly after a new version of PHP comes out.
Other optimizers include ionCube PHP Accelerator (PHPA) and Zend Optimizer+, which is a part of Zend Server.
However, if you plan to run your website on PHP 5.x and need a small memory footprint, you're willing to make do with only community support, and you're not afraid to experiment, I strongly suggest that you go for PHP eAccelerator. The performance improvement should make your website's users happy.
Allowed tags: <a> link, <b> bold, <i> italics