How to Increase PHP Performance

I needed to upgrade PHP on my servers. I run a mix of Windows 2008 and Windows 2003 servers using IIS. I had been doing quit a bit of research the last couple weeks. My research taught me a few things. PHP for Windows has evolved to the point that it can run as well on Windows as it does on Linux servers without the errors we used to see. I’m not going to get into them since anyone that has been running Windows Servers with PHP for any length of time will be able to tell you about the errors that were common.

Now on to the steps I took to increase the performance of my PHP websites running on Windows 2008 and Windows 2003 with IIS. At the end of the article I’ll supply links to the downloads I used.

My previous configuration had PHP 5.2.3 running in ISAPI mode with thread safe binaries. There were no options for non-thread safe binaries at the time. I think they first became available with 5.3.0 and in later versions of the 5.2 branch. With 5.3.0 the ISAPI extension is deprecated so you have no choice but to use CGI. CGI by itself is much slower than ISAPI and there are no accelerators such as xcache that will work it. I’m not going to get into the difference between thread safe and non-thread safe in PHP. Instead I’ll direct to a blog post on which give you a brief description of the 2. View it here.

On my Windows 2003 servers I upgraded PHP to 5.2.12 non thread safe. I changed all the sites so that they used the CGI binary. There is no ISAPI filter for IIS in the NTS downloads. After I had PHP configured with the extensions I needed to be loaded, you’ll need the NTS extensions since thread safe extensions will not work, I turned IIS back online and recycled the app pools for each site. As expected the site was slower with this configuration and loads on the server increased.

The next step was to download the FastCGI wrapper. I downloaded it and installed it on the server. I then set up the fast cgi ini to use the PHP cgi binary and set the basic configuration. Once that was done I set each site to use the fast cgi binary to serve pages. I then recycled the app pools again. I checked the site again and the speed of each site was better than it had ever been with ISAPI and xcache. The load on the server was also lower than it had ever been. After the site ran all night I noticed I was getting some timeouts on certain scripts. I was able to correct that by tweaking the fast cgi ini. For one I had to make sure the timeout for script execution was the same as it is in php.ini. I also added a few other changes that seem to have increased performance even more that the default install.

My final fast cgi ini looks like this:



The only downside to using fast cgi is none of the opcode caches like xcache work with it. While fast cgi by itself gave the server a serious speed improvement over ISAPI I had got used to having xcache installed. I then found a post about an opcode cache built specifiably for Windows Server running fast cgi. It’s called wincache. I downloaded it and installed it. To my surprise page load times decreased again and server load was next to nothing.

For Windows 2003 servers you can’t go wrong with NTS binaries with fast cgi and wincache.

Now that I had my Windows 2003 servers done I went on to the Windows 2008 Servers. This was much easier since the fast cgi wrapper is already the way you run php on Windows 2008. I had been running thread safe versions of PHP so when I upgraded PHP I went to 5.3.1 NTS using the vc9 build. I noticed a slight speed increase. Not as much as I did on the Windows 2003 servers, but, an increase none the less.

I then installed wincache. After 24 hours I now see a marked performance increase on the Windows 2008 servers.

So if you want to give your Windows Servers a shot in the arm switch to PHP non thread safe with fast cgi and wincache. You’ll be glad you did.

Here are the links to the downloads you’ll need.

Fast CGI wrapper for IIS 6
wincache download page

Leave a Reply

3 Comments on "How to Increase PHP Performance"

Notify of
Don Raman
Hi, Very nice blog post. I am part of PHP/FastCGI (which is part of IIS Team) product development team in Microsoft. Using FastCGI with NTS build of PHP along with WINCACHE wil significantly boost your PHP application performance. Another significant feature we added in the FastCGI 1.5 release for IIS 5.1/6.0 is the real-time tuning of MaxInstances setting. This MaxInstances setting dictates the maximum number of FastCGI processes which can be launched for each application pool. If it is set to 0 then FastCGI extension will automatically adjust the number of instances up or down every few seconds based on… Read more »

[…] increase is tremendous. If you want to check out my blog post about the performance increase here is the link. Memcached does nothing to help performance unless you are using more than one memcached server. […]