Optimizing PHP, Part Three
This article shows you how to configure and compile PHP for maximum performance.
Thursday, September 7th, 2006
Last month’s “Tech Support” column showed you how to install and configure the Alternative PHP Cache to speed up your PHP applications without changing any code. This month, let’s go one level deeper in the stack and tune your PHP installation itself.
While pre-packaged binaries are convenient, high-traffic sites typically need a roll-your-own PHP and Apache to fine-tune features and yield extra performance. Start with the latest version of PHP. The 5.1x branch has finally brought PHP 5 performance up to an acceptable level, and includes many advances over PHP 4. After downloading and unpacking the latest version of PHP 5 (5.1.4 as the magazine went to press), set your CFLAGS, an environment variable for compiler flags that are passed to gcc. The correct compiler flags depend on what kind of machine you have, what kind of CPU you have, how much cache the CPU has, and a variety of other factors.
Here are two examples, the first for the Xeon processor and the other for the Opteron.
$ export CFLAGS="–march=pentium4 –O3
–pipe –msse2 –mfpmath=sse,387
–mmmx –fomit-frame-pointer
–prefer-non-pic”
$ export CFLAGS="–march=opteron –O3
–pipe –msse2 –m3dnow
–fomit-frame-pointer –mtune=opteron”