Boost Your PHP Processing Speed


I never paid much attention in the past to compiler options when building PHP or any other applications for that matter. A simple configure, make, make install was enough for me to get most things going.

I was a little troubled with some benchmarking that I've been doing, though and I started looking for ways to increase my throughput. I found a few references to CFLAGS parameters and how they can increase performance with php, so I put them to the test.

After seeing the above referenced sites, I researched a little bit on what settings would work best for my particular server. That involved a little bit of man page reading (man gcc), and a little bit of googling - because apparently, gcc either has different flags for different platforms or nobody can spell who has a page up about CFLAGS optimization.

For my particular case, the following command set my CFLAGS appropriately:

collapsehide line numbers
Sample Code
 1<br />
 2export CFLAGS="-O3 -march=pentium4 -fomit-frame-pointer -funroll-loops -mfpmath=sse"<br />
Code ©SteveKallestad.com

That's an O3 not a zero3. The first flag, O3, sets the optimization level. Since I don't plan on doing any debugging, I used the highest value. The second flag, march, optimizes the compilation for my cpu architecture. There were several pentium-ish options, so I checked out /proc/cpuinfo for as much information as I could garner about my CPUs. The third flag, fomit-frame-pointer, is problematic for debugging, but it clears a register for functions that don't need a frame pointer. The next flag, funroll-loops, makes for a larger code base by unrolling predictable sized loops and by doing so, it speeds up processing. The mfpmath flag optimizes the code for my particular floating point processor.

I recompiled php, apache, and eaccellerator after setting these flags up, and found something very interesting.

Running basic apachebench tests, I did not see, as I expected, an increase in the number of Requests per second that I could handle. What I did see, is a dramatic reduction in the mean time-per-request with greater levels of concurrency. My pages don't process any faster, but I can handle multiple concurrent requests much more smoothly.



Discuss Boost Your PHP Processing Speed