Accelerate your PHP scripts
This was something that I was meaning to do for quite a while and I finally got around to doing it this morning.
Back a few days ago Donncha wrote on his blog about eAccelerator. Essentially this is “an accelerator, optimizer, encoder and dynamic content cache for PHP.” What that means is that instead of compiling your PHP pages each time someone visits your site, eAccelerator keeps each PHP page compiled and cached after the first visit. This greatly speeds up access to each page and reduces server load.
Since my server is under very little load anyway this wasn’t the reason I wanted to try it out. I wanted to try it to see if it would speed things up any bit as my upstream here is only 384k. I grabbed the source and followed the quick start instructions to the letter and lo and behold it was simple to install. But what about performance?
Before installing I ran a quick benchmark from another machine that I have here on this blogs index page using Apache Bench (ab). Once this was complete and the results noted I enabled eAccelerator and viewed the page once in my browser to add it to the cache and then ran the benchmark again. The benchmark command I used was as follows:
ab -n 100 http://blog.sweetnam.eu/index.php
Simple as that! They say that results speak for themselves so here they are.
Before installing eAccellerator:
Time taken for tests: 33.727772 seconds
Complete requests: 100
Failed requests: 34
Requests per second: 2.96 [#/sec] (mean)
Time per request: 337.278 [ms] (mean)
Transfer rate: 97.69 [Kbytes/sec] received
And after installation:
Time taken for tests: 20.97849 seconds
Complete requests: 100
Failed requests: 0
Requests per second: 4.98 [#/sec] (mean)
Time per request: 200.978 [ms] (mean)
Transfer rate: 163.95 [Kbytes/sec] received
Pretty conclusive. It almost doubled the performance. Well worth it. Of course this test was performed across my LAN so I have no idea how well it performs via the web yet but it looks promising.
Is your blog hosted in your office? You should use mod_gzip or enable gzip compression in php.ini (there are plenty of tutorials out there explaining how) and your web pages will be compressed quite a bit. Don’t bother with compression level over 3, I usually opt for 1.
Hi Donncha, I’ve been using mod_gzip since I set this server up sometime ago.
Indeed it is hosted in my home office. The webserver itself is overkill for what it is serving up.