PHP installation on IIS: ISAPI or CGI?

The Non-Thread-Safe PHP CGI binary for Windows is supposed to give you maximum stability, compatibility and performance as:

  1. PHP was originally designed and optimized for multi-process environment
  2. Most of the extensions were created keeping that in mind
  3. There is no "waiting" that you see in multi-threaded environments

However, the performance and stability is susceptible when the CGI binary is used in multi-threaded environments such as IIS. Therefore most people have started using the relatively new FastCGI extension that is available for IIS 5.1/IIS 6.0 as a download and bundled with IIS7.

This guide explains how to install and configure PHP CGI with Microsoft's FastCGI extension.

The second option is to go for PHP ISAPI but be sure to (i) use Thread-Safe builds (ii) use stable and tested extensions -- the PHP ISAPI can otherwise crash and take down IIS as well. A side note is that tread-safety in PHP is like a hand-brake that is always engaged; some even say that it is a myth.

Update: PHP ISAPI is not shipped anymore so the question about ISAPI vs. CGI is not a question anymore. FastCGI is recommended.

  1. FastCGI support is built into modern versions of IIS, you just need to enable it.
  2. PHP installer presents the option of installing PHP with FastCGI.
  3. For people who want to perform ZIP installations can use "PHP Manager for IIS" to configure PHP installation with IIS.

I personally find for non busy websites (e.g. between 0-25 users on average) ISAPI works fine, I have found little benefit to using CGI over ISAPI.

However, If you have a busy website or do not mind putting a bit of work in to it, I recommend looking at FastCGI as you can now get it on Win2003 IIS6, It runs MUCH faster under heavy loads.

http://www.iis.net/extensions/FastCGI


CGI performs very poorly on IIS as compared to the ISAPI model (since creating new processes, which is how CGI works, is very "expensive" in Windows NT-dervied operating systems). In modern versions of IIS many of the "probems" of ISAPI (memory leaks, needing to "recycle" applications, etc) are "fixed" and ISAPI-based applications generaly work very well and are easy to manage. Any reasons you find re: CGI-based applications being "better" than ISAPI-based applications were probably written in an IIS 4.0 or IIS 5.0-era mindset.