FastCGI Application <application>

Overview

The FastCGI <application> element contains the configurations settings for a specific FastCGI process pool definition. When FastCGI is used, IIS will use the value in the maxInstances attribute of the <application> element to determine the number of FastCGI processes that can run in the process pool.

The simplest FastCGI application pool definition requires that you include the fullPath attribute in an <application> element to define the binaries to use for the specific application framework. For the PHP framework, set the fullPath attribute to the directory and file name of the PHP binaries.

Other attributes are optional and let you configure a number of other parameters. These include the maximum number of requests that a FastCGI worker process can process before it is recycled, the maximum number of worker processes for an application pool, and the maximum amount of time a FastCGI request can take.

Note

In order to process requests by using FastCGI, you must first map the path and the specific file name extensions to the FastCGI module and specify the target FastCGI process as the script processor.

New in IIS 7.5

IIS 7.5 added the following attributes to the <fastCgi>/<application> element:

  • The monitorChangesTo attribute lets you specify a file to monitor for changes that might affect the behavior of a FastCGI application. For example, if you use the PHP framework, you can configure IIS to monitor the PHP.INI file for changes by specifying the full path to the file in the monitorChangesTo attribute.
  • The stderrMode attribute specifies how IIS 7 will handle errors that are returned from a FastCGI application through the STDERR stream.
  • The signalBeforeTerminateSeconds attribute lets you configure IIS to wait for a specified period of time after IIS signals a FastCGI application that it needs to shut down. This lets a FastCGI application clean up any settings before IIS terminates the process.

Compatibility

Version Notes
IIS 10.0 The <application> element was not modified in IIS 10.0.
IIS 8.5 The <application> element was not modified in IIS 8.5.
IIS 8.0 The default value of the maxInstances attribute was changed from 4 to 0 in IIS 8.0.
IIS 7.5 The <application> element of the <fastCgi> collection was updated in IIS 7.5 with the monitorChangesTo, stderrMode, and signalBeforeTerminateSeconds attributes.
IIS 7.0 The <application> element of the <fastCgi> collection was introduced in IIS 7.0.
IIS 6.0 N/A

Setup

To use the FastCGI environment, you must first install the CGI role service. The installation process registers the Common Gateway Interface (CGI) role service in both the <globalModules> and <modules> elements. You do not need to perform any other steps to install the FastCGI environment.

Windows Server 2012 or Windows Server 2012 R2

  1. On the taskbar, click Server Manager.
  2. In Server Manager, click the Manage menu, and then click Add Roles and Features.
  3. In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.
  4. On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Application Development, and then select CGI. Click Next.
    Screenshot of the Server Roles dialog box. C G I is checked and highlighted.
  5. On the Select Features page, click Next.
  6. On the Confirm installation selections page, click Install.
  7. On the Results page, click Close.

Windows 8 or Windows 8.1

  1. On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows features on or off.
  3. Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select CGI.
    Screenshot of the windows Features dialog box. C G I is selected in the expanded menu.
  4. Click OK.
  5. Click Close.

Windows Server 2008 or Windows Server 2008 R2

  1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
  2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
  3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
  4. On the Select Role Services page of the Add Role Services Wizard, select CGI, and then click Next.
    Screenshot of the Role Services page. C G I is highlighted.
  5. On the Confirm Installation Selections page, click Install.
  6. On the Results page, click Close.

Windows Vista or Windows 7

  1. On the taskbar, click Start, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
  3. Expand Internet Information Services, then select CGI, and then click OK.
    Screenshot of the Windows Features dialog box. C G I is highlighted.

How To

Note for IIS 7.0 users: Some of the steps in this section may require that you install the Microsoft Administration Pack for IIS 7.0, which includes a user interface for FastCGI settings. To install the Microsoft Administration Pack for IIS 7.0, see the following URL:

How to create a global FastCGI handler mapping for PHP

Note

Before the following procedure will work, you must have already installed binaries that will execute the file path or file name extension that you specify. This example uses a PHP implementation available from www.php.net.

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, click the server name for which you want to configure FastCGI handler mappings.

  3. In the Home pane, double-click Handler Mappings.
    Screenshot of the Default Web Site Home page. The icon for Handler Mappings is highlighted.

  4. In the Actions pane, click Add Module Mapping
    Screenshot of the I I S Manager window displaying the Handler Mappings page.

  5. Enter the following information:

    • Enter the file name extension in the Request path text box. For example, "*.php".

    • Click FastCgiModule in the Module drop-down list.

    • Enter the path to the scripting engine in the Executable box. For example, "C:\PHP\php-cgi.exe".

    • Enter a unique name for the handler mapping in the Name box. For example, "PHP-FastCGI".

      Screenshot of the Add Module Mapping dialog box.

    • Click Request Restrictions

    • Select Invoke handler only if request is mapped to.

    • Click to select the File or Folder option.

    • Click OK.

      Screenshot of the Request Restrictions dialog box.

  6. Click OK.

  7. If you are prompted to create a FastCGI application in the Add Module Mapping dialog box, click Yes.

    Screenshot of the Add Module Mapping information dialog box.

    Note

    This will automatically create a FastCGI application for the handler mapping that you just created. If you choose No, you can manually create a FastCGI application later.

How to create a FastCGI application for PHP

Note

Before the following procedure will work, you must have already installed binaries that will execute the file path or file name extension that you specify. This example uses a PHP implementation available from www.php.net.

Note

Adding a FastCGI application does not automatically add a handler mapping. To do so, follow the steps in the How to create a global FastCGI handler mapping for PHP section of this article.

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, click the server name for which you want to configure FastCGI settings.

  3. In the Home pane, double-click FastCGI Settings.

    Screenshot of the Server Home page. The Fast C G I Settings is highlighted.

  4. In the Actions pane, click Add Application.

    Screenshot of the Fast C G I Settings page in I I S Manager.

  5. In the Add FastCGI Application dialog box, enter the following information:

    • Enter the path to the scripting engine in the Full Path box. For example, "C:\PHP\php-cgi.exe".

    • Enter the maximum number of requests for the FastCGI application.

      Note

      For PHP, this number must be lesser or equal to the maximum number of requests for PHP environment, which is configured by using the PHP_FCGI_MAX_REQUESTS environment variable.

      Screenshot of the Add Fast C G I Application dialog box.

  6. Click the ellipsis (...) next to EnvironmentVariables to open the environment variables collection editor.

  7. In the EnvironmentVariables Collection Editor dialog box, click Add.

    Screenshot of the Environment Variables Collection Editor dialog box.

  8. Enter the following information, and then click OK.

    • Enter "PHP_FCGI_MAX_REQUESTS" for the Name.

    • Enter "10000" for the Value.

      Screenshot of the Environment Variables Collection Editor dialog box. P H P F C G I Max Requests is highlighted in the Members field.

  9. Click OK to close the Add FastCGI Application dialog box.

How add a FastCGI environment variable for PHP

Note

Before the following procedure will work, you must have already installed binaries that will execute the file path or file name extension that you specify. This example uses a PHP implementation available from www.php.net.

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, click the server name for which you want to configure FastCGI settings.

  3. In the Home pane, double-click FastCGI Settings.

    Screenshot of the Server Home page in I I S Manager. THe icon for Fast C G I Settings is highlightd.

  4. Highlight the PHP application in the FastCGI Settings pane, then click Edit in the Actions pane.

    Screenshot of the Fast C G I Settings page within I I S Manager.

  5. In the Edit FastCGI Application dialog box, click the ellipsis (...) next to EnvironmentVariables to open the environment variables collection editor.

    Screenshot of the Edit Fast C G I Application dialog box.

  6. In the EnvironmentVariables Collection Editor dialog box, click Add.

    Screenshot of the Environment Variables Collection Editor pane.

  7. Enter the following information, and then click OK.

    • Enter "PHP_FCGI_MAX_REQUESTS" for the Name.

    • Enter "10000" for the Value.

      Screenshot of the Environment Variables Collection Editor pane. P H P F C G I is highlighted.

  8. Click OK to close the Add FastCGI Application dialog box.

Configuration

You can configure the <application> element at the server level in the ApplicationHost.config file or at the site level, application level, or directory level in a Web.config file.

Attributes

Attribute Description
activityTimeout Optional uint attribute.

Specifies the maximum time, in seconds, that a FastCGI process can take to process. Acceptable values are in the range from 10 through 3600.

The default value in IIS 7.0 is 30; the default for IIS 7.5 is 70.
arguments Optional string attribute.

Specifies the command-line arguments for the FastCGI process.
flushNamedPipe Optional Boolean attribute.

Specifies whether named pipes are flushed at the end of each request. This property applies only when the named-pipe protocol is used.

The default value is false.
fullPath Required string attribute.

Specifies the full path of the FastCGI process.
idleTimeout Optional uint attribute.

Specifies the maximum amount of time, in seconds, that a FastCGI process can be idle before the process is shut down. Acceptable values are in the range from 10 through 604800.

The default value is 300.
instanceMaxRequests Optional uint attribute.

Specifies the maximum number of requests that can be processed by each FastCGI worker process before it is recycled. Acceptable values are in the range from 1 through 10000000.

The default value is 200.
maxInstances Optional uint attribute.

Specifies the maximum number of FastCGI worker processes that can be started in an application pool. Acceptable values are in the range from 0 through 10000.

The default value is 0.
monitorChangesTo Option string attribute.

Specifies the full path to a file to monitor for changes. When changes to the file are detected, IIS will terminate and restart the FastCGI application that is specified in the fullPath attribute.

Note: This attribute was added in IIS 7.5.

There is no default value.
protocol Optional enum attribute.

Specifies the transport mechanism that is used to communicate with the FastCGI process.

The protocol attribute can be one of the following possible values:
Value Description
NamedPipe The named-pipe protocol will be used to communicate with the FastCGI worker process.
Tcp The TCP protocol will be used to communicate with the FastCGI worker process.
The default value is NamedPipe.
queueLength Optional uint attribute.

Specifies the maximum number of requests that can be queued for a FastCGI process pool. Acceptable values are in the range from 1 through 10000000.

The default value is 1000.
requestTimeout Optional uint attribute.

Specifies the maximum time, in seconds, that a FastCGI process request can take. Acceptable values are in the range from 10 through 604800.

The default value is 90.
signalBeforeTerminateSeconds Optional uint attribute.

Specifies the amount of time that IIS will wait after IIS signals a FastCGI application that it needs to shut down. When this attribute is set to a value greater than zero, IIS will create an inheritable event and pass the handle value for the event to a FastCGI process as value of _FCGI_SHUTDOWN_EVENT_ environment variable.

Note: This attribute was added in IIS 7.5.

The default value is 0.
stderrMode Optional enum attribute.

Specifies the behavior that IIS will use for errors that FastCGI applications return in the STDERR stream.

Note: This attribute was added in IIS 7.5.

The stderrMode attribute can be one of the following possible values:
Value Description
ReturnStdErrIn500 Specifies that IIS will return an HTTP 500 error and display the content in the STDERR stream to the client. (Note: This matches the IIS 7.0 behavior.)

The numeric value is 0.
ReturnGeneric500 Specifies that IIS will return a generic HTTP 500 error to the client. This prevents the content in the STDERR stream from being returned to the client.

The numeric value is 1.
IgnoreAndReturn200 Specifies that IIS will ignore the text in the STDERR stream and return an HTTP 200 error, and return the content of the STDOUT stream to the client.

The numeric value is 2.
TerminateProcess Specifies that IIS will terminate the FastCGI process and return a generic HTTP 500 error to the client.

The numeric value is 3.
The default value is ReturnStdErrIn500.

Child Elements

Element Description
environmentVariables Optional element.

Specifies a collection of environment variables that IIS will pass to the FastCGI application.

Configuration Sample

The following configuration sample adds a FastCGI application for PHP, sets the instanceMaxRequests attribute to "10000," and sets the PHP_FCGI_MAX_REQUESTS environment variable to "10000."

<fastCgi>
   <application fullPath="C:\PHP\php-cgi.exe"
         arguments=""
         maxInstances="4"
         idleTimeout="300"
         activityTimeout="30"
         requestTimeout="90"
         instanceMaxRequests="10000"
         protocol="NamedPipe"
         flushNamedPipe="false">
      <environmentVariables>
         <environmentVariable
            name="PHP_FCGI_MAX_REQUESTS"
            value="10000" />
      </environmentVariables>
   </application>
</fastCgi>

Note

For PHP, the value of the PHP_FCGI_MAX_REQUESTS environment variable must be a number that is lesser or equal to the value specified by the instanceMaxRequests attribute of the FastCGI <application> element.

The following configuration sample adds a global FastCGI handler mapping for PHP files to IIS and specifies the full path to a FastCGI executable file.

<configuration>
   <location path="" overrideMode="Allow">
      <system.webServer>
         <handlers>
            <add name="PHP-FastCGI"
                path="*.php"
                verb="GET,HEAD,POST"
                modules="FastCgiModule"
                scriptProcessor="C:\PHP\php-cgi.exe"
                resourceType="Either"
                requireAccess="Script" />
         </handlers>
      </system.webServer>
   </location>
</configuration>

Note

FastCGI settings can be configured per-site through the use of specially formatted FastCGI application and by handler mappings, which are distinguished by matching the fullPath and arguments attributes for an <application> element with the corresponding scriptProcessor attribute in the <handlers> mapping for the FastCGI process. To create these mappings, the settings in the fullPath and arguments attributes for an <application> element must be added to the scriptProcessor attribute in the <handlers> mapping for the FastCGI process and separated by the pipe "|" character. This combination serves as a unique key for each FastCGI application. For example, the following configuration excerpt shows two example <fastCgi>/<application> elements and their corresponding <handlers> mappings for two site-specific PHP handlers:

<fastCgi>
   <application fullPath="C:\PHP\php-cgi.exe"
      arguments="-d open_basedir=C:\Websites\Website1" />
   <application fullPath="C:\PHP\php-cgi.exe"
      arguments="-d open_basedir=C:\Websites\Website2" />
</fastCgi>

<system.webServer>
   <handlers accessPolicy="Read, Script"> 
      <add name="PHP via FastCGI 1"
         path="*.php"
         verb="*"
         modules="FastCgiModule"
         scriptProcessor="C:\PHP\php-cgi.exe|-d open_basedir=C:\Websites\Website1"
         resourceType="Unspecified"
         requireAccess="Script" />
      <add name="PHP via FastCGI 2"
         path="*.php"
         verb="*"
         modules="FastCgiModule"
         scriptProcessor="C:\PHP\php-cgi.exe|-d open_basedir=C:\Websites\Website2"
         resourceType="Unspecified"
         requireAccess="Script" />
</handlers>
</system.webServer>

Sample Code

The following code samples add a FastCGI application for PHP, set the instanceMaxRequests attribute to "10000," and set the PHP_FCGI_MAX_REQUESTS environment variable to "10000." Each sample also adds a global FastCGI handler mapping for PHP files to IIS and specifies the full path to a FastCGI executable file.

AppCmd.exe

appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe',arguments='',maxInstances='4',idleTimeout='300',activityTimeout='30',requestTimeout='90',instanceMaxRequests='10000',protocol='NamedPipe',flushNamedPipe='False']" /commit:apphost

appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']" /commit:apphost

appcmd.exe set config -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='C:\PHP\php-cgi.exe',resourceType='Either',requireAccess='Script']" /commit:apphost

Note

You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();

         ConfigurationSection fastCgiSection = config.GetSection("system.webServer/fastCgi");
         ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();
         ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");
         applicationElement["fullPath"] = @"C:\PHP\php-cgi.exe";
         applicationElement["arguments"] = @"";
         applicationElement["maxInstances"] = 4;
         applicationElement["idleTimeout"] = 300;
         applicationElement["activityTimeout"] = 30;
         applicationElement["requestTimeout"] = 90;
         applicationElement["instanceMaxRequests"] = 10000;
         applicationElement["protocol"] = @"NamedPipe";
         applicationElement["flushNamedPipe"] = false;

         ConfigurationElementCollection environmentVariablesCollection = applicationElement.GetCollection("environmentVariables");
         ConfigurationElement environmentVariableElement = environmentVariablesCollection.CreateElement("environmentVariable");
         environmentVariableElement["name"] = @"PHP_FCGI_MAX_REQUESTS";
         environmentVariableElement["value"] = @"10000";
         environmentVariablesCollection.Add(environmentVariableElement);
         fastCgiCollection.Add(applicationElement);

         ConfigurationSection handlersSection = config.GetSection("system.webServer/handlers");
         ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
         ConfigurationElement addElement = handlersCollection.CreateElement("add");
         addElement["name"] = @"PHP-FastCGI";
         addElement["path"] = @"*.php";
         addElement["verb"] = @"GET,HEAD,POST";
         addElement["modules"] = @"FastCgiModule";
         addElement["scriptProcessor"] = @"C:\PHP\php-cgi.exe";
         addElement["resourceType"] = @"Either";
         addElement["requireAccess"] = @"Script";
         handlersCollection.AddAt(0, addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration

      Dim fastCgiSection As ConfigurationSection = config.GetSection("system.webServer/fastCgi")
      Dim fastCgiCollection As ConfigurationElementCollection = fastCgiSection.GetCollection
      Dim applicationElement As ConfigurationElement = fastCgiCollection.CreateElement("application")
      applicationElement("fullPath") = "C:\PHP\php-cgi.exe"
      applicationElement("arguments") = ""
      applicationElement("maxInstances") = 4
      applicationElement("idleTimeout") = 300
      applicationElement("activityTimeout") = 30
      applicationElement("requestTimeout") = 90
      applicationElement("instanceMaxRequests") = 10000
      applicationElement("protocol") = "NamedPipe"
      applicationElement("flushNamedPipe") = False

      Dim environmentVariablesCollection As ConfigurationElementCollection = applicationElement.GetCollection("environmentVariables")
      Dim environmentVariableElement As ConfigurationElement = environmentVariablesCollection.CreateElement("environmentVariable")
      environmentVariableElement("name") = "PHP_FCGI_MAX_REQUESTS"
      environmentVariableElement("value") = "10000"
      environmentVariablesCollection.Add(environmentVariableElement)
      fastCgiCollection.Add(applicationElement)

      Dim handlersSection As ConfigurationSection = config.GetSection("system.webServer/handlers")
      Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection
      Dim addElement As ConfigurationElement = handlersCollection.CreateElement("add")
      addElement("name") = "PHP-FastCGI"
      addElement("path") = "*.php"
      addElement("verb") = "GET,HEAD,POST"
      addElement("modules") = "FastCgiModule"
      addElement("scriptProcessor") = "C:\PHP\php-cgi.exe"
      addElement("resourceType") = "Either"
      addElement("requireAccess") = "Script"
      handlersCollection.AddAt(0, addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST");
var fastCgiCollection = fastCgiSection.Collection;
var applicationElement = fastCgiCollection.CreateNewElement("application");
applicationElement.Properties.Item("fullPath").Value = "C:\\PHP\\php-cgi.exe";
applicationElement.Properties.Item("arguments").Value = "";
applicationElement.Properties.Item("maxInstances").Value = 4;
applicationElement.Properties.Item("idleTimeout").Value = 300;
applicationElement.Properties.Item("activityTimeout").Value = 30;
applicationElement.Properties.Item("requestTimeout").Value = 90;
applicationElement.Properties.Item("instanceMaxRequests").Value = 10000;
applicationElement.Properties.Item("protocol").Value = "NamedPipe";
applicationElement.Properties.Item("queueLength").Value = 1000;
applicationElement.Properties.Item("flushNamedPipe").Value = false;
applicationElement.Properties.Item("rapidFailsPerMinute").Value = 10;

var environmentVariablesCollection = applicationElement.ChildElements.Item("environmentVariables").Collection;
var environmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable");
environmentVariableElement.Properties.Item("name").Value = "PHP_FCGI_MAX_REQUESTS";
environmentVariableElement.Properties.Item("value").Value = "10000";
environmentVariablesCollection.AddElement(environmentVariableElement);
fastCgiCollection.AddElement(applicationElement);

var handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST");
var handlersCollection = handlersSection.Collection;
var addElement = handlersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "PHP-FastCGI";
addElement.Properties.Item("path").Value = "*.php";
addElement.Properties.Item("verb").Value = "GET,HEAD,POST";
addElement.Properties.Item("modules").Value = "FastCgiModule";
addElement.Properties.Item("scriptProcessor").Value = "C:\\PHP\\php-cgi.exe";
addElement.Properties.Item("resourceType").Value = "Either";
addElement.Properties.Item("requireAccess").Value = "Script";
handlersCollection.AddElement(addElement, 0);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")
Set fastCgiCollection = fastCgiSection.Collection
Set applicationElement = fastCgiCollection.CreateNewElement("application")
applicationElement.Properties.Item("fullPath").Value = "C:\PHP\php-cgi.exe"
applicationElement.Properties.Item("arguments").Value = ""
applicationElement.Properties.Item("maxInstances").Value = 4
applicationElement.Properties.Item("idleTimeout").Value = 300
applicationElement.Properties.Item("activityTimeout").Value = 30
applicationElement.Properties.Item("requestTimeout").Value = 90
applicationElement.Properties.Item("instanceMaxRequests").Value = 10000
applicationElement.Properties.Item("protocol").Value = "NamedPipe"
applicationElement.Properties.Item("queueLength").Value = 1000
applicationElement.Properties.Item("flushNamedPipe").Value = false
applicationElement.Properties.Item("rapidFailsPerMinute").Value = 10

Set environmentVariablesCollection = applicationElement.ChildElements.Item("environmentVariables").Collection
Set environmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable")
environmentVariableElement.Properties.Item("name").Value = "PHP_FCGI_MAX_REQUESTS"
environmentVariableElement.Properties.Item("value").Value = "10000"
environmentVariablesCollection.AddElement(environmentVariableElement)
Call fastCgiCollection.AddElement(applicationElement)

Set handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST")
Set handlersCollection = handlersSection.Collection
Set addElement = handlersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "PHP-FastCGI"
addElement.Properties.Item("path").Value = "*.php"
addElement.Properties.Item("verb").Value = "GET,HEAD,POST"
addElement.Properties.Item("modules").Value = "FastCgiModule"
addElement.Properties.Item("scriptProcessor").Value = "C:\PHP\php-cgi.exe"
addElement.Properties.Item("resourceType").Value = "Either"
addElement.Properties.Item("requireAccess").Value = "Script"
Call handlersCollection.AddElement(addElement, 0)

adminManager.CommitChanges()