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 IIS.net 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.Posted on
Categories :News and Information