As my first topic I am going to discuss PHP performance boosting utility eAccelerator. I am currently working on a PHP based web project that fires off about 30 XMLHttpRequests in succession. The response of each call is displayed on the website and needed after the completion of all the requests where the responses are added to a database. PHP session variables were a possibility however speed could easily become an issue since PHP would be handling many simultaneous sessions and the values would have the be retrieved from the hard disk. Alternatively a database based session handler might be faster but certainly not practical with so many commands being executed in succession. Cookies would have worked for most users however I do not recommend relying on cookies when the sole functionality of an application depends on them.

I also wanted to store the responses for quick retrieval, which are very small, ranging from a few bytes to half a kilobyte, since it is likely different users will request the same information frequently. With this in mind, neither of the previous options were ideal. Ideally the responses could be stored in memory and the PHP functions have the ability to quickly set and retrieve data. Obviously you would not want to try and store a multitude of very large objects in memory however in my case I could store thousands of key-value pairs using a small block of memory. This is where eAccelerator became a practical match for my application. It is among a few PHP memory caching options available such as XCache and Memcache. Although eAccelerator is first and foremost a PHP cache utility to store compiled scripts it also features the ability use memory as a temporary store for information through a powerful API.

On to the installation process… If you run a dedicated server with CPanel/WHM there is an option in the Easy Apache configuration wizard to compile with eAccelerator. Unfortunately, with the latest version of eAccelerator the put and get functions are not enabled on a default compile so I had to take the installation to command line. Keep in mind that you will need root access to be able to recompile Apache. The process I followed is below.

  • Download the latest release 0.9.5.2 from http://eaccelerator.net/wiki/Release-0.9.5.2
  • Upload the script to your server and extract the package
  • CD to the directory
  • Run export PHP_PREFIX=”/usr/lib” where “/usr/lib” is the location of your PHP installation
  • Run ‘phpize’ if you are running multiple php branches to bootstrap eAccelerator by executing $PHP_PREFIX/bin/phpize
  • Run ./configure –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config –with-eaccelerator-shared-memory
  • There are other configuration options such as session support, a full list of options is available at http://eaccelerator.net/wiki/CompileConfiguration
  • Run make
  • Run make install
  • Locate your php.ini file and locate the eAccelerator configuration section where you can set default garbage collection times, storage options, and memory allocation. You can find more information about the settings at http://eaccelerator.net/wiki/InstallFromSource
  • You need to make sure that the cache directory referenced in your php.ini is created and the chmod is set to 0777.

Now you can create a simple test PHP script to put a key-value pair into memory and another to get the value of the key you added. A simple put command would look like “eaccelerator_put($key, $value, $ttl)” where $value is the time period in seconds that the key should be stored before being discarded. To retrieve the key’s value you can simply run the command “eaccelerator_get($key)”. You can find complete API details at http://bart.eaccelerator.net/doc/phpdoc/.

By default if you are in a shared environment this functionality will be extended to everyone but you can disable eAccelerator on a per-domain level in your vhosts file. Extending the get/put methods to all users in a shared environment could potentially be dangerous. If you create a phpinfo() file you can monitor the memory usage, number of cached scripts and number of stored keys.

So, how much does this really help? You should see a nice drop in CPU utilization since PHP scripts will be more efficiently compiled and since they are served from memory as long as you have memory available the response time is noticeably quicker. Overall I didn’t see any real performance compromises by enabling eAccelerator. Obviously you will be using more memory but you have control over the amount that is used for storage. After the max is reached then scripts and keys are stored in the cache directory reference in the php.ini file. If you are running PHP, have extra memory available and have root access then I highly recommend eAccelerator to increase server speed and add valuable functionality to store, retrieve and remove data in memory. There are a number of practical applications for this utility.

Posted by Michael in Apache,PHP,Performance on April 17, 2008

18 Responses

eAccelerator is very fast (I’ve seen huge improvements too in our server), but unfortunatelly it is not stable.

I have used it on a production server with huge traffic and php 4.x and got problems with Apache. In fact ea caused many crashes and we finally disabled it from the server.

Nick on April 21, 2008 at 8:54 am

@Nick – I am also running eAccelerator on one of my production servers with heavy traffic and have yet to run into any problems. Perhaps it was the combination of your PHP, Apache and eAccelerator versions or the configuration somehow? I am running Apache, PHP 5.2.5 and eAccelerator 0.9.5.2. I will definitely keep and eye on it and update my post if I run into issues. Thanks for the input.

Michael on April 21, 2008 at 9:01 am

I suppose that is the case. I was using php4 with apache 1.3

Nick on April 22, 2008 at 4:17 am

Hi. I’ve run some benchmarks with eAccelerator and some other OpCode Caches (plus Zend Optimizer). The text is in german, but you should be able to get the main conclusions from the graphs and tables alone:

http://blogs.interdose.com/dominik/2008/04/11/benchmarking-php-eaccelerator-und-andere-opcode-caches/

(Graphs show duration in seconds for 10 000 requests of several different scripts)

My conclusion is: You really should have an OpCode Cache (e.g. eAccelerator) installed on your machine.

Dominik on April 22, 2008 at 4:26 am

@Dominik – Thanks for the link. I had not gotten around to doing any formal benchmarks yet. Those numbers are very impressive.

Michael on April 22, 2008 at 7:59 am

I agrre from our test EA is faster AND more stable. Then APC then xcache.

The GUI for EA is very poor however. Not even uptime or hits/misses.

James on May 05, 2008 at 11:00 pm

Running aAccelerator without any problem.

Conducting to a friend suggestion, I have replaced Apache with Nginx and PHP as FastCGI, running hundred times faster, for Web Servers with heavy load.

It’s quite limited, but it’s fast.

Sebastian Zavadschi on April 29, 2009 at 5:24 pm

Another great tip: when building eaccelerator from source, don't forget to add –with-eaccelerator-sessions. This will allow sessions to be handled by eaccelerator increasing session performance. Great for linux hosts using shared memory (SHM). cPanel does not enable session support for eaccelerator by default, so its important to not build eaccelerator from easyapache but better to build it after. Be sure that if there is more than one PHP installation to use the right phpize binary when building. We make sure that eaccelerator is enabled on every server where PHP is installed. It is a great performance boost!

Good find, maybe update your post with this information?

Cubichost on August 08, 2009 at 4:33 pm

Hey, could anyone help me? I Need to install eAccelerator for my website. How to do it? I read an article but i don't understand. How to run those commands? :( (

Italas777 on January 17, 2010 at 9:08 am

We've use eAccelerator on one of our project and fortunately we haven't encounter any problems yet. If we do i will definitely go here and ask.

College Papers on January 26, 2010 at 9:49 pm

Hello! I had problems with eAccelerator.
I was loosing data from session. (I have array in session.)
Now I turned it off and looks like everything fine.

Zord on February 16, 2010 at 3:37 am

Ive had lots of problems with eAccelerator in the past, I switched to apc a few years ago as it seems to be the most stable and best performing from all the caching systems i tried.

Web Development on March 04, 2010 at 6:38 am

Really great information in your blog. Please write more so that we can get more updates in your blog. Thanks a lot!regardssears parts

rjeka hotels on August 07, 2010 at 4:55 pm

We have tested this previously and have seen great results, Thanks for article

Craig on August 26, 2010 at 6:46 am
Comments are closed at this time.