Share via


IIS 6.0 - FastCGI

CGI application were discouraged on IIS webservers because for every request a new host process had to be spawned raising questions about performance.

The FastCGI protocol is set to change this. The concept is simple instead of creating a new host process for each request and killing it ...reuse a bunch(or single) of processes to handle the requests.

You gain significant performance improvement by reusing the process instead of killing it and creating a new one.

How do I start ?

You can download the installer here

FastCGI Extension for Internet Information Services 6.0

INSTALLATION

The installation is pretty simple. It basically copies three files to your \system32\inetsrv folder. The files are

fcgiconfig.js       - Script file that can be use to configure FastCGI settings(you can change configurations manually as well)

fcgiext.dll          - The ISAPI extension that helps in passing requests to the CGI process.

fcgiext.ini         - The settings file that controls the behavior of  the FastCGI handler (If you do not feel like using fcgiconfig.js you have to tweak this file)

It also adds an entry in IIS Web Service Extensions "FastCGI Handler" and enables it.

In case you are uninstalling FastCGI extension note that the ini file is left intact on the server. In future if you reinstall FastCGi you may find some settings already configured because of this.

CONFIGURATION

FCGICONFIG.JS is the configuration script that you use to configure FastCGI settings (You can always do it manually as well)

Using fcgiconfig.js will give you a first hand experience on how changing IIS 7 configuration from command line will look.

fcgicongif

cscript fcgiconfig.js -add -section:"PHP" - extension:php -path: "C:\php-5.2.5-nts-Win32\php-cgi.exe"

(You can use the -site switch if you want to configure only one website)

What this does is it puts an ISAPI extensions mapping for .php and points it to the fcgiext.dll

isapiextension

It also adds entries in the fcgiext.ini file mapping to tell the fcgi handler  which cgi executable is mapped to the .php extension.

[Types]
php=PHP

[PHP]
ExePath=C:\php-5.2.5-nts-Win32\php-cgi.exe

It then recycles the apppools in case of IIS 6.0 or restarts the service in IIS 5.0

If you have multiple mappings say for PHP and RoR then in IIS both the extensions will be mapped to fcgiext.dll but in the fcgiext.ini we will specify which executable to use to handle the requests.

The above image shows a clear difference as to how a CGI application configured with FastCGI looks. If you notice I even have the perl cgi mapped to ".pl" in the above image. It is mapped as CGI. But in case of ".php" it is mapped to the FastCGI handler(fcgiext.dll) which now in turn will invoke the "php-cgi.exe" as required.

So for every "*.pl" request a new instance of perl.exe process is created but for ".php" requests the process(es) is reused.

By default the FastCGI handler creates a pool of 10 CGI processes. This can be tweaked using the MaxInstances parameter in the ini file. The fcgiext.ini can be used to tweak the following parameters Protocol / MaxInstances / QueueLength / IdleTimeout / ActivityTimeout / RequestTimeout / InstanceMaxRequests / ResponseBufferLimit / FlushNamedPipe / UnhealthyOnQueueFull / IgnoreExistingFiles / IgnoreExistingDirectories

So now when a request is made for a php file IIS hands off the request to the fcgiext.dll ISAPI extension. The FastCGI handler then checks the association in the [Types] section. It then spawns the corresponding CGI process and hands off the request to the executable. Once the request is processed and returned back the process is not killed but kept alive till IdleTimeout (300 sec default). If another request for a php file is made the same process is reused.

Bookmark and Share

Comments

  • Anonymous
    December 12, 2007
    Can I use FastCGI with IIS5.0?

  • Anonymous
    December 14, 2007
    Paco it is only supported on IIS 6.0. Thank you for reporting it.

  • Anonymous
    January 28, 2008
    @vijaysk FastCGI is also supported for iis 5.1

  • Anonymous
    March 28, 2008
    Thank you, easy clear instructions. Every other thing I searched for directed me to some very outdated instructions. Very easy!

  • Anonymous
    June 29, 2009
    I see in the docs that the default Protocol setting is NamedPipe, but how does fcgiext.dll figure out what the name of the NamedPipe is? Does it piece together ".pipeFastCGIphp-cgi" from the ExePath?

  • Anonymous
    October 05, 2009
    Hi, I am an advanced level user of Moodle. Recently, I migrated from Vista to XP and attempting to rebuild the moodle on XP. I installed moodle 1.9-20090923 on IE 5.1 with MySQL db directly from IIS's http://www.microsoft.com/web/gallery/ After a lot of struggle, I was able to manage the FASTCGI extension working and the site started working. I restored old courses, (were perfectly alright before)onto new server. Restoration of data seems ok (except the embedded images in Topic are broken), linking of videos is fine but the video won't play in any of the browsers (Safari, Chrome, IE6) on my machine. Therefore, it is not a browser-specific problem. Has someone faced similar problem? Is it a IIS 5.1 related problem? Please help!!! Example url - http://localhost/classroom/file.php/6/Workshop_PPTs/blah-%20Blah%2C%20Blah%20Blah%20Blah%20follow-up%20tests.wmv Moodle keeps the data in a folder called "moodledata". The URL formation has to happen in such a way that it the data is read from this folder, wherever it is kept. I have kept it on C drive. Logs observed- The logs show following (but essentially 404) 2009-10-04 12:22:58 127.0.0.1 - W3SVC1 VYAS 127.0.0.1 80 GET /classroom/file.php - 404 3 4203 663 0 HTTP/1.1 localhost Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.648;+.NET+CLR+3.5.21022;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729) SESScfc90a62c81b7bfc6f292320b1d0b8ca=2ac9jq68a45gno7i2uumvgdr96;+MoodleSession=5h29fgts1e81cr87ur5ufnh1v4;+MoodleSessionTest=rqiUUPplPk;+MOODLEID_=%25E2%25C6%251FU%25B1u%25B1%2509%25F7F%25F5 http://localhost/classroom/mod/resource/view.php?inpopup=true&id=29 2009-10-04 12:22:58 127.0.0.1 - W3SVC1 VYAS 127.0.0.1 80 GET /classroom/file.php - 404 3 4203 433 16 HTTP/1.1 localhost NSPlayer/11.0.5721.5265+WMFSDK/11.0 SESScfc90a62c81b7bfc6f292320b1d0b8ca=2ac9jq68a45gno7i2uumvgdr96;+MoodleSession=5h29fgts1e81cr87ur5ufnh1v4;+MoodleSessionTest=rqiUUPplPk;+MOODLEID_=%25E2%25C6%251FU%25B1u%25B1%2509%25F7F%25F5 - 2009-10-04 12:23:09 127.0.0.1 - W3SVC1 VYAS 127.0.0.1 80 GET /classroom/file.php - 404 3 4203 433 0 HTTP/1.1 localhost NSPlayer/11.0.5721.5265+WMFSDK/11.0 SESScfc90a62c81b7bfc6f292320b1d0b8ca=2ac9jq68a45gno7i2uumvgdr96;+MoodleSession=5h29fgts1e81cr87ur5ufnh1v4;+MoodleSessionTest=rqiUUPplPk;+MOODLEID_=%25E2%25C6%251FU%25B1u%25B1%2509%25F7F%25F5 - 2009-10-04 12:23:11 127.0.0.1 - W3SVC1 VYAS 127.0.0.1 80 GET /classroom/file.php - 404 3 4203 854 0 HTTP/1.1 localhost Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.648;+.NET+CLR+3.5.21022;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729) SESScfc90a62c81b7bfc6f292320b1d0b8ca=2ac9jq68a45gno7i2uumvgdr96;+MoodleSession=5h29fgts1e81cr87ur5ufnh1v4;+MoodleSessionTest=rqiUUPplPk;+MOODLEID_=%25E2%25C6%251FU%25B1u%25B1%2509%25F7F%25F5 http://localhost/classroom/mod/resource/view.php?inpopup=true&id=29