PHP on IIS7 w/FastCGI

Posted: Oct 31, 2006  54 comments  

Average Rating

Tags
IIS News Item
IIS7
PHP
Samples & Demos

I'm attending ZendCon today and giving a demo in the keynote presentation by Andi Gutmans, one of the creators of PHP, and co-founder of Zend.  I'm psyched to show off IIS7 and PHP along-side Andi!

I only have 5 mins to demo, so I decided to focus the demo on two things:  1) how easy it is to get PHP up and running and 2) the early results of our collaboration on performance for PHP on Windows.

 

Demo Preparation

Throughout the demo I'll be using Qdig, a simple, but powerful image gallery application.  Setup of Qdig is really easy. To use the thumbnails and image resize features of Qdig, make sure you've enabled the GD library in your php.ini file.  Download the zip file, unzip it to C:\inetpub\qdig, grab some of your favorite images and place them in a subdirectory, then - as described in the install.txt file - allow IUSR and NetworkService full control of the qdig-files directory, browse to the site once, then re-set permissions back to read/execute.

Part of this demo is measuring the performance gains we've made.  To simulate load on the application, I'll be using an application called 'WCat', short for Web Capacity Analysis tool.  It is a VERY powerful tool, and we'll only be scratching the surface of what it can do.  The version of WCat that I'm using is in the IIS6 resource kit.  There are some cool tools in there, and while they haven't been tested on IIS7, most of them do work.  Once you've downloaded the resource kit, and installed it, proceed to the next step.

I've setup a simple wcat script to test my QDig performance.  You can download the zip file with .bat and configuration scripts here.  Unzip to C:\demo\performance and check out the contents.  ThomaD gave me these a while back, and I've been tweaking them ever since.  startStress.bat will launch both the controller, and the client, which will pound the URLs found in php_script.cfg for about 10 seconds.  You'll see a quick summary of the results after the test has run. 

I wanted to do something useful with Windows Sidebar during the demo, so I created my very first gadget last weekend, which you can download from the Gadget Gallery site.  It launches perfmon, or any other configured path (I configure mine to launch my c:\demo\performance\perfmon.msc file, which has the get requests/sec perf counter).

 

Installing PHP on IIS7

The first part of the demo follows the steps of my previous blog post, and is really straight forward.  The steps are described in this post titled: How to install PHP on IIS7 (RC1).  Once I've got PHP installed, I run my performance test using that fancy gadget and get the following results:

PHP.net download performance using ISAPI (fast, but unreliable) - (full size image)

As you can see, I'm getting a little over 60 requests per second.  This is about as fast as PHP can go today, using the community distribution of PHP from http://www.php.net/.  ISAPI runs PHP inside the IIS worker process on multiple threads, making it similar to ASP or ASP.NET.  Unfortunately, since some PHP extensions aren't yet threadsafe, running it in this way usually leads to crashes.

Installing IIS7' FastCGI module & PHP 

As a result of the collaboration between Microsoft and Zend, there is now a faster and more reliable way to run PHP.  The first step is to download the new IIS FastCGI feature, available as a Technical Preview release on this page of the IIS.net site.  Download and unzip it to c:\fastCGI. 

The next step is to download PHP itself.  You can, of course, use the IIS FastCGI feature with the community distribution of PHP which we downloaded for the first demo.  If you want the latest PHP core engine performance enhancements from Zend, you can also download a Technical Preview here.  This zip file contains a special build of PHP for this Technical Preview, and is for experimental use only.  Please don't ask Zend for support.  I unzipped my copy to C:\zendPHP.

I should also mention that if you want to try Zend's Core product, which contains Zend's fastCGI implementation as well as some other cool features and tools, you can download from Zend.  Zend's products are eligible for full support, and are truly Enterprise-class software.  We plan to work with Zend in the future to enable Microsoft's FastCGI feature to integrate closer with Zend's products.

Once you've unpacked both the fastCGI module, as well as the PHP distribution you're ready to use, run the fastCGI installer like this:

Install FastCGI and register PHP handler (full size image)

Now that you've got the FAST version of CGI installed, and the handler re-mapped, run our performance benchmark again and see the results (shown side-by-side the previous run for comparison):

FastCGI performance rocking! (full size image)

 

Wow!  Despite the fact that Microsoft and Zend just started working together, the results look very, very good.  The FastCGI + Zend PHP numbers for Qdig, on my laptop, are almost twice what I get from today's PHP.  And don't forget, Zend has committed to submit the performance enhancements back to the PHP community, so they will be showing up soon in the usual PHP.net distributions.  

In addition to the great performance, the FastCGI method of running PHP should be significantly more stable than the ISAPI method.  This is because with FastCGI, PHP is still running single-threaded in one or more processes in the FastCGI pool.   

 

IIS Kernel Mode Caching for PHP applications 

Of course, this is just the start for PHP developers.  Once they're on Windows and IIS7, there are a ton of cool features to begin taking advantage of like distributed configuration, a sexy new admin tool for IIS configuration, diagnostic tools like failed request tracing, .NET integration (think ASP.net forms auth for a PHP app!) and more - all of which are unique to IIS7.  One of the cool things that I wanted to show off, while we're talking about performance, is the new output cache. 

The IIS7 output cache is a new feature in IIS7 which makes it possible to cache entire responses in memory - even from dynamic content.  Unlike the existing caches IIS has, it is a 'smart' cache, enabling you to configure it to cache separate copies of responses for the same page (like index.php) based on query string value, so it works great for the Qdig application we've been using.  One of the other really cool things about it is the fact that it is integrated with the http.sys (kernel mode driver) cache, allowing for blazing fast performance.  Output caching is going to be a very powerful feature for all kinds of applications, from PHP to ColdFusion, Classic ASP to CGI.  It will work with any content type, and can significantly speed up performance for applications where the underlying data doesn't change (like our image gallery), or where the changes occur at a predictable rate (so you can timeout the cache at the expected interval).  Even in cases where the data is changing, say, once a second, it may make great sense to use the output cache with an expiration of 1 second.  This allows for the dynamic processing to occur only once a second, instead of on every request, significantly speeding up response times and lowering CPU. 

To configure output caching for QDig's index.php page, we first need to "unlock" the <caching> configuration section.  Open \windows\system32\inetsrv\config\applicationhost.config file and search for <caching>.  Cut it from it's current location, then search for (<location path="" - without parenthesis) and paste the caching configuration section in below it like this:

<location path="" overrideMode="Allow">
   <system.webServer>
      <caching enabled="true" enableKernelCache="true" />

The point here is to move it under the section of applicationhost.config that is marked as overrideMode="Allow", which enables it to be set at the application level.

Now that you've unlocked it, create a web.config in your QDig directory, and paste in the following configuration:

<configuration>
  <location path="index.php">
     <system.webServer>
       <caching>
         <profiles>
            <add extension=".php" location="Any" kernelCachePolicy="CacheUntilChange" varyByQueryString="Qwd,Qif,Qiv,Qis" />
         </profiles>
       </caching>
     </system.webServer>
  </location>
</configuration>

Now that you've got kernel caching configured, run the performance test again.  Before you do that, you may want to change the scale of your perfmon chart from (0..100) to (0.8,000). :)  Here is what I get with kernel caching enabled:

Kernel Mode Caching PHP responses @ 6000 requests per second! (full size image)

To be honest, I'd expect it to be even faster. It would normally be in the 10s of thousands. The main reason it isn't is that I'm running the client and server on the same box, and any client generating 6000 RPS is going to use quite a bit of CPU, limiting the time slice kernel has to use. But going from 100+ RPS to 6000RPS isn't to shabby, eh?

One of the cool things in Vista is a new command line tool that will show you what is in the http.sys cache.  Run "netsh http show cache" to get a snapshot:

NetSh cmd-line tool showing http.sys cache  (full size image)

 

Summary

IIS' new FastCGI feature is going to be a huge benefit for web application frameworks like PHP which expect single-threaded environments.  It lets them run fast and reliably on Windows, and begin take advantage of all the cool features of IIS.  Using it, along with Zend's PHP enhancements in this demo almost doubled QDig performance on my machine, and made it much more stable. 

To make sure anyone can take advantage of FastCGI on all of our existing platforms, we've built an ISAPI version of it that can run on Windows XP and Windows 2003 (IIS 5.1 and IIS 6.0) as well as a new module version for IIS 7.0.  Check out the IIS FastCGI page for more information. 

Technorati Profile

Comments

  1. BillS' IIS Blog
    October 31, 2006

    I&#39;m attending ZendCon today and giving a demo in the keynote presentation by Andi Gutmans, one of

  2. All About Interop
    October 31, 2006

    Bill Staples of Microsoft blogged on the newly announced partnership between Zend and Microsoft, one

  3. alexbarnett.net blog
    October 31, 2006

    Microsoft and Zend have issued a press release on news regarding collaboration between the two companies

  4. tecosystems
    November 1, 2006

    BillS' IIS Blog : PHP on IIS7 w/FastCGI Bill gave an excellent demo of some of the new PHP support here at the Zend conference (tags: zendconference2006 IIS PHP Microsoft) P@ Log » Blog Archive » Migrating to WordPress...

  5. tecosystems
    November 1, 2006

    Been an eventful day, to say the least, at the first non-tutorial day of Zend's annual gathering of a couple of hundred PHP developers and vendors. Not in terms of announcements, necessarily, though Zend did unveil both a hosted solution...

  6. ScottGu's Blog
    November 1, 2006

    I've blogged several times in the past about how cool IIS 7.0 is. Many of my posts have highlighted some

  7. Mischa Kroon
    November 1, 2006
    Does this mean IIS will become the best / fastest choice for hosting PHP applications soon ?
  8. 菊池 Blog
    November 1, 2006

    IIS7 の FastCGI は激速らしい

  9. bills
    November 1, 2006

    Mischa: I certainly hope so!

  10. Mike Moore
    November 1, 2006
    Hey Bill, this is great news. Have you guys benchmarked Ruby on Rails performance on IIS7 using FastCGI?
  11. bills
    November 1, 2006

    Hey Mike: nope, we haven't had a chance to test Ruby yet (just getting it out the door in time for ZendCon was a big effort).  Let us know if you get a chance to try it out, and how it looks.

  12. Ancora Imparo
    November 1, 2006

    Microsoft is cranking out a lot of stuff. Two things I am very eagerly awaiting are Linq and IIS 7.0.

  13. Fiorano.net
    November 2, 2006

    M icrosoft kondigde een paar dagen geleden een Technical Preview Release van FastCGI voor IIS aan. Deze

  14. JrzyShr Dev Guy
    November 2, 2006

    The Zend/PHP Conference &amp; Expo is going on this week out in San Jose, California. Bill Hilf, from

  15. orson
    November 3, 2006

    This is GREAT news! Really groovy development. Microsoft is putting its might to support and enhance an open source technology like PHP5 for the first time. Finally, wisdom dawns on the behemoth regarding the win-win situation for web- developer centric enhancements like the kernel-mode cacheing for php applications! SUN better look out now......

  16. scottgu
    November 3, 2006

    我过去写过几个博客帖子,都是写 IIS 7.0 是多么地酷的。我的很多帖子着重于 IIS7 给 ASP.NET 和 .NET 开发人员带来的新机遇,譬如集成的管道模型,统一的web.config 配置,集成的管理工具体验等。它真的将给开发人员开辟出巨大的机遇,以及提供给大家一个可以无限定制的web服务器。

  17. BillS' IIS Blog
    November 8, 2006

    My first experiment with building a Windows Sidebar gadget was more for show than anything. Launching

  18. BillS' IIS Blog
    November 9, 2006

    Thanks to some small tweaks we made in RC1, it is now easier than EVER to get PHP working on IIS. Here

  19. Roger Meier
    November 10, 2006

    FastCGI support on IIS is just a great Idea! Thank's

    On the preview Release I miss some advanced features(eg. IP, Portnumber) used for distributed environments.

    please have a look at lighttpd's FastCGI Configuration:

    http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI

  20. Arnold Smit
    November 15, 2006

    First I used PHP5 as ISAPI.

    On my test server i have experimented with the new FastCGI extention, and i was suprised how much inprovement that was.

    It was way faster than the ISAPI.

    Nowdays i also use PHP5 in combination with Eaccelerator and FastCGI.

    It is very stable and astonishingly fast.

    This is the website were you can download the Windows binaries for Eaccelerator.

    http://www.sitebuddy.com/PHP/Accelerators/eAccelerator_windows_binaries_builds

    The official site is.

    http://eaccelerator.net/

    If you want a speed boost i realy sugest using PHP as FastCGI with the Eaccelerator Extention

  21. Windows Server Division WebLog
    November 17, 2006

    Last Tuesday in front of over 4000 attendees, Jeffrey Snover and Bob Muglia announced the release of

  22. server-side
    November 22, 2006

    Before hopping on the plane and starting my Thanksgiving vacation, here are some highlights about the new IIS7 Native Output Cache, PHP, FastCGI, and other stuff ...

  23. Hiroshi Okunushi's blog
    December 4, 2006

    実は説明の中でこれに興味を持っていただいた方がいらっしゃって一体どうやって動いてるんだろう?というのが議論になりました。そこで少し情報収集。。。 まずはIISの親分Bill Staplesのところへ http://blogs.iis.net/bills/archive/2006/10/31/PHP-on-IIS.aspx

  24. Hoster Poster
    January 5, 2007

    Not particularly new news now, but if you haven&#39;t started investigating PHP on Windows yet, here&#39;s

  25. BillS' IIS Blog
    March 28, 2007

    Carlos and I spoke at the Microsoft Technology Summit yesterday, a conference dedicated to influential

  26. danieli
    April 14, 2007

    Here’s where we used to be when it came to interoperability. 1980 was the best of times and it was the

  27. BillS' IIS Blog
    April 25, 2007

    Today we're very excited to announce the Beta 3 release of IIS7 as part of Longhorn Server. IIS7 is the

  28. Hiroshi Okunushi's Blog ☆ミ
    April 26, 2007

    Virtualization、管理(田辺さん)、PowerShell、ターミナルサービスが目立って人が入っていたような気がしました。やはり関心高いですね。(^。^)y-.。o○ 私のIIS7.0もかなりの数のお客様がご入場くださいました。ありがとうございます!実はIISとしては今日米国で大きな動きがいくつかありましてその内容も盛り込もうとしたり、会場ではIIS7が初めてのお客様も多かった関係でやはり時間が足りないセッションになってしまったという反省をしております。もうそろそろIISだけで複数セッション必要な時期が来たと思っています

  29. DNN Deployment
    April 30, 2007

    http://blogs.iis.net/bills/archive/2006/10/31/PHP-on-IIS.aspx

  30. BillS' IIS Blog
    May 2, 2007

    IIS7 has a new output cache feature that can cache dynamic content (output from your ASP.NET, Classic

  31. Scott Hanselman's Computer Zen
    October 29, 2007
  32. Scott Hanselman
    November 2, 2007

    Hello Dear Reader. I have been working with IIS7 for a while and I&#39;m convinced that it&#39;s the

  33. Drew's IIS Blog
    November 2, 2007

    You may have heard about the new interoperability improvements for PHP and Microsoft technologies that

  34. Noticias externas
    November 2, 2007

    You may have heard about the new interoperability improvements for PHP and Microsoft technologies that

  35. Radoslaw Zawartko » PHP@Windows - ISAPI vs fastCGI vs Phalanger
    November 10, 2007

    Pingback from  Radoslaw Zawartko &raquo; PHP@Windows - ISAPI vs fastCGI vs Phalanger

  36. Mike Volodarsky's ServerSide
    November 12, 2007

    Just over a year after the we first announced the FastCGI (see the first ever blog post about it: mvolo.com/.../Making-PHP-rock-on-Windows_2F00_IIS.aspx

  37. FastCGI for IIS is Released, PHP On IIS Faster Than On Apache
    November 13, 2007

    Pingback from  FastCGI for IIS is Released, PHP On IIS Faster Than On Apache

  38. FastCGI for IIS Final Released, Congratulations to the IIS Team! at The NeoSmart Files
    November 15, 2007

    Pingback from  FastCGI for IIS Final Released, Congratulations to the IIS Team! at  The NeoSmart Files

  39. A few things you may not already know
    November 25, 2007

    Le cordonnier; qui n'a décidément peur de rien; a pris deux décisions importantes, la première utiliser

  40. PHP Access Violation [ IIS + ISAPI ] - WHM cPanel Destek Platformu
    November 26, 2007

    Pingback from  PHP Access Violation [  IIS + ISAPI ] - WHM cPanel Destek Platformu

  41. Wp Wordpress » Blog Archive » FastCGI for IIS is Released, PHP On IIS Faster Than On Apache
    December 16, 2007

    Pingback from  Wp Wordpress  &raquo; Blog Archive   &raquo; FastCGI for IIS is Released, PHP On IIS Faster Than On Apache

  42. blog.gerke-preussner.de
    February 8, 2008

    I finally had some time to upgrade the software for this blog and learned a couple interesting things in the process. This article explains how to install PHP in IIS 7.0 on the 64-bit version of Windows Vista and get Serendipity up and running.Installing

  43. IIS7, PHP and WordPress on Vista « verb. sap.
    May 12, 2008

    Pingback from  IIS7, PHP and WordPress on Vista &laquo; verb. sap.

  44. iis blog software
    June 1, 2008

    Pingback from  iis blog software

  45. Using PHP in IIS Server-- Daily Gems
    August 13, 2008

    Pingback from  Using PHP in IIS Server-- Daily Gems

  46. IIS7??????PHP?????????LAMP?????????100?????? at 5IVI4I_I_60Y
    December 16, 2008

    Pingback from  IIS7??????PHP?????????LAMP?????????100??????  at 5IVI4I_I_60Y

  47. IIS7??????PHP?????????LAMP?????????100?????? at 5IVI4I_I_60Y
    December 16, 2008

    Pingback from  IIS7??????PHP?????????LAMP?????????100??????  at 5IVI4I_I_60Y

  48. Microsoft Partners With Zend | keyongtech
    January 21, 2009

    Pingback from  Microsoft Partners With Zend | keyongtech

  49. IIS7 php 5 et phpmyadmin(mysql) | hilpers
    January 22, 2009

    Pingback from  IIS7 php 5 et phpmyadmin(mysql) | hilpers

  50. IIS7 php 5 et phpmyadmin(mysql) | hilpers
    January 22, 2009

    Pingback from  IIS7 php 5 et phpmyadmin(mysql) | hilpers

  51. Web Development Community
    March 10, 2009

    You are voted (great) - Trackback from Web Development Community