Open Source Software Technical Articles

Want the Best of the Wazi Blogs Delivered Directly to your Inbox?

Subscribe to Wazi by Email

Your email:

Connect with Us!

Current Articles | RSS Feed RSS Feed

Improve PHP performance with PHP eAccelerator

  
  
  

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.

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.

Configuring PHP eAccelerator

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
extension="eaccelerator.so"

; shared memory size in magabytes
eaccelerator.shm_size="16"

; the directory to be used as disk cache
eaccelerator.cache_dir="/tmp/eaccelerator"

; "1" to enable the eaccelerator, 0 to disable it
eaccelerator.enable="1"

; "1" to enable the code optimizer, 0 to disable it
eaccelerator.optimizer="1"

; "1" to enable the php file modification checking, 0 to disable it
eaccelerator.check_mtime="1"

; "1" to enable the debug logging, 0 to disable it
eaccelerator.debug="0"

; Determine which PHP files must be cached. You can give wild cards here.
eaccelerator.filter=""

; 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.
eaccelerator.shm_ttl="0"

; 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.
eaccelerator.shm_prune_period="0"

; Enables or disables caching of compiled scripts on disk.
eaccelerator.shm_only="0"

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:

<?php
  phpinfo(); 
?

Open the file on your site and you should see an entire section of details on eAccelerator.

eaccelerator resized 600

Similar PHP optimizers

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.




This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.
Tags: ,

Comments

g
Posted @ Sunday, April 07, 2013 1:18 AM by nikoleta
Very nice article thank you for this. I am going to use this for a cPanel server.
Posted @ Thursday, September 19, 2013 10:55 PM by Alex
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics