
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.
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.
April 23, 2013
March 22, 2013
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 – 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.
I suppose that is the case. I was using php4 with apache 1.3
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 – Thanks for the link. I had not gotten around to doing any formal benchmarks yet. Those numbers are very impressive.
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.
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.
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?
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?
(
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.
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.
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.
I expect more than that from your blog so keep it up and great blog comparing to other one's you will give me the procedure for that because i was waiting for the replay I like to subscribe this blog. <a href="http://www.eluminoustechnologies.com/php_programming.htm">PHP Programming</a>
Done a excellent job in this blog, Alternatively create a great blog for the readers specially for PHP programming. Thanks.
Good analyze every points clearly and meaningfully are given. Thanks
Pretty! You describe the topic very well. Thanks once again for the push!
I came to your blog just when I was surfing on this topic. I am happy that I found your blog and information I wanted.
<a href="http://www.boundlesstech.net">Web Design</a>
These tips and tricks are very useful for me to trace many links and networks. Thanks, <a href="http://www.cdrates.org">highest rate cd</a>