FastCGI アプリケーション <application>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

FastCGI <application> 要素には、特定の FastCGI プロセス プール定義の構成設定が格納されます。FastCGI が使用されている場合、IIS は <application> 要素の maxInstances 属性の値に基づいて、プロセス プールで実行できる FastCGI プロセス数を判定します。

互換性

  IIS 7.0 IIS 6.0
注意 <fastCgi> コレクションの <application> は IIS 7.0 で新たに導入された要素です。

なし

セットアップ

FastCGI 環境を使用するには、まず CGI 役割サービスをインストールする必要があります。インストール プロセスにより、<globalModules> および <modules> の両方の要素で CGI (Common Gateway Interface) 役割サービスが登録されます。FastCGI 環境をインストールするために他の手順を実行する必要はありません。

Windows Server 2008

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] ウィンドウのツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[CGI] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーで [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. コントロール パネルで、[プログラムと機能][Windows の機能の有効化または無効化] の順にクリックします。

  3. [Internet Information Services] を展開し、[CGI] を選択して [OK] をクリックします。

    拡大

方法

: このセクションの手順の一部では、FastCGI 設定用のユーザー インターフェイスが含まれている Microsoft Administration Pack for IIS 7.0 のインストールを求められる場合があります。Microsoft Administration Pack for IIS 7.0 をインストールするには、次の URL を参照してください。

http://learn.iis.net/page.aspx/415/

PHP 用のグローバル FastCGI ハンドラー マッピングを作成する方法

: このセクションの手順の操作を行うには、指定するファイル パスまたはファイル名拡張子を実行するバイナリを既にインストールしている必要があります。この例では、www.php.net (英語) で入手できる PHP 実装を使用します。

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、FastCGI ハンドラー マッピングを構成するサーバー名をクリックします。

  3. [ホーム] ウィンドウで [ハンドラー マッピング] をダブルクリックします。

    拡大

  4. [操作] ウィンドウで [モジュール マップの追加] をクリックします。

    拡大

  5. 次の情報を入力して [OK] をクリックします。

    • [要求パス] テキスト ボックスにファイル名拡張子を入力します。例 : 「*.php」
    • [モジュール] ドロップダウン リストで [FastCgiModule] をクリックします。
    • [実行可能ファイル] ボックスに、スクリプト エンジンへのパスを入力します。例 : 「C:\PHP\php-cgi.exe」
    • [名前] ボックスに、ハンドラー マッピングの一意の名前を入力します。例 : 「PHP-FastCGI」

    拡大

  6. [モジュール マップの追加] ダイアログ ボックスで、FastCGI アプリケーションを作成するかどうかを確認するプロンプトが表示されたら、[はい] をクリックします。

    拡大

    : 作成したハンドラー マッピングに対する FastCGI アプリケーションが自動的に作成されます。[いいえ] をクリックすると、Fast CGI アプリケーションを後で手動で作成できます。

PHP 用の FastCGI アプリケーションを作成する方法

: このセクションの手順の操作を行うには、指定するファイル パスまたはファイル名拡張子を実行するバイナリを既にインストールしている必要があります。この例では、www.php.net (英語) で入手できる PHP 実装を使用します。

: FastCGI アプリケーションを追加しても、ハンドラー マッピングは自動的に追加されません。ハンドラー マッピングを追加するには、このトピックの 「PHP 用のグローバル FastCGI ハンドラー マッピングを作成する方法」の手順に従ってください。

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、FastCGI 設定を構成するサーバー名をクリックします。

  3. [ホーム] ウィンドウで [FastCGI Settings] をダブルクリックします。

    拡大

  4. [操作] ウィンドウで [アプリケーションの追加] をクリックします。

    拡大

  5. [Add FastCGI Application] ダイアログ ボックスで、次の情報を入力します。

    • [完全なパス] ボックスに、スクリプト エンジンへのパスを入力します。例 : 「C:\PHP\php-cgi.exe」
    • FastCGI アプリケーションに対する要求の最大数を入力します。**
      注** : PHP の場合、この数字は、PHP 環境に対する要求の最大数以下に設定する必要があります。PHP 環境に対する要求の最大数は、PHP_FCGI_MAX_REQUESTS 環境変数を使用して構成されます。

    拡大

  6. [EnvironmentVariables] の横にある省略記号をクリックして、環境変数コレクション エディターを開きます。

  7. [EnvironmentVariables Collection Editor] ダイアログ ボックスで、[追加] をクリックします。

    拡大

  8. 次の情報を入力して [OK] をクリックします。

    • [名前] に「PHP_FCGI_MAX_REQUESTS」と入力します。
    • [値] に「10000」と入力します。

    拡大

  9. [OK] をクリックして、[Add FastCGI Application] ダイアログ ボックスを閉じます。

PHP 用の FastCGI 環境変数を追加する方法

: このセクションの手順の操作を行うには、指定するファイル パスまたはファイル名拡張子を実行するバイナリを既にインストールしている必要があります。この例では、www.php.net (英語) で入手できる PHP 実装を使用します。

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続]/ ウィンドウで、FastCGI 設定を構成するサーバー名をクリックします。

  3. [ホーム] ウィンドウで [FastCGI Settings] をダブルクリックします。

    拡大

  4. [FastCGI Settings] ウィンドウで PHP アプリケーションを強調表示し、[操作] ウィンドウで [編集] をクリックします。

    拡大

  5. [Edit FastCGI Application] ダイアログ ボックスで、[EnvironmentVariables] の横にある省略記号をクリックして、環境変数コレクション エディターを開きます。

    拡大

  6. [EnvironmentVariables Collection Editor] ダイアログ ボックスで、[追加] をクリックします。

    拡大

  7. 次の情報を入力して [OK] をクリックします。

    • [名前] に「PHP_FCGI_MAX_REQUESTS」と入力します。
    • [値] に「10000」と入力します。

    拡大

  8. [OK] をクリックして、[Add FastCGI Application] ダイアログ ボックスを閉じます。

構成

サーバー レベルでの <application> 要素の構成は ApplicationHost.config ファイルで、サイト レベル、アプリケーション レベル、またはディレクトリ レベルでのこの要素の構成は Web.config ファイルで、それぞれ設定できます。

属性

属性 説明
activityTimeout オプションの unit 属性。

FastCGI プロセスの最大処理時間 (秒) を指定します。許容できる値は、10 から 3600 の範囲内の値です。

既定値は 30 です。
arguments オプションの string 属性。

FastCGI プロセスのコマンドライン引数を指定します。
flushNamedPipe オプションの Boolean 属性。

各要求の終わりに名前付きパイプを消去するかどうかを指定します。このプロパティは、名前付きパイプ プロトコルの使用時にのみ適用されます。

既定値は false です。
fullPath 必須の string 属性。

FastCGI プロセスの完全なパスを指定します。
idleTimeout オプションの unit 属性。

FastCGI プロセスをシャットダウンするまでの最大アイドル時間 (秒) を指定します。許容できる値は、10 から 604800 の範囲内の値です。

既定値は 300 です。
instanceMaxRequests オプションの unit 属性。

各 FastCGI ワーカー プロセスをリサイクルするまでに、それぞれのプロセスで処理できる最大要求数を指定します。許容できる値は、1 から 10000000 の範囲内の値です。

既定値は 200 です。
maxInstances オプションの unit 属性。

1 つのアプリケーション プールで起動できる FastCGI ワーカー プロセスの最大数を指定します。許容できる値は、1 から 10000 の範囲内の値です。

既定値は 4 です。
protocol オプションの enum 属性。

FastCGI プロセスとの通信に使用するトランスポート機構を指定します。

protocol 属性には、次のいずれかの値を指定できます。

既定値は NamedPipe です。
値              説明 
-----        --------------------------------------------------------
NamedPipe     FastCGI ワーカー プロセスとの通信に、名前付きパイプ プロトコルを使用します。 
Tcp           FastCGI ワーカー プロセスとの通信に、TCP プロトコルを使用します。 
queueLength オプションの unit 属性。

1 つの FastCGI プロセス プールでキューに書き込める最大要求数を指定します。許容できる値は、1 から 10000000 の範囲内の値です。

既定値は 1000 です。
requestTimeout オプションの unit 属性。

FastCGI プロセス要求の最大所要時間 (秒) を指定します。許容できる値は、10 から 604800 の範囲内の値です。

既定値は 90 です。

子要素

要素 説明
environmentVariables オプションの要素。

IIS から FastCGI アプリケーションに渡す環境変数のコレクションを指定します。

構成サンプル

次の構成サンプルでは、PHP 用の FastCGI アプリケーションを追加し、instanceMaxRequests 属性を "10000" に、PHP_FCGI_MAX_REQUESTS 環境変数を "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>

: PHP の場合、PHP_FCGI_MAX_REQUESTS 環境変数の値は、FastCGI <application> 要素の instanceMaxRequests 属性によって指定される値以下に設定する必要があります。

次の構成サンプルでは、PHP ファイル用のグローバル FastCGI ハンドラー マッピングを IIS に追加し、FastCGI 実行可能ファイルへの完全なパスを指定しています。

<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="Unspecified"
                requireAccess="Script" />
         </handlers>

      </system.webServer>
   </location>
</configuration>

サンプル コード

次のコード サンプルでは、PHP 用の FastCGI アプリケーションを追加し、instanceMaxRequests 属性を "10000"に、PHP_FCGI_MAX_REQUESTS 環境変数を "10000" に設定しています。また、どのサンプルでも、PHP ファイル用のグローバル FastCGI ハンドラー マッピングを IIS に追加し、FastCGI 実行可能ファイルへの完全なパスを指定しています。

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='Unspecified',requireAccess='Script']" /commit:apphost

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"] = @"Unspecified";
         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") = "Unspecified"
      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 = "Unspecified";
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 = "Unspecified"
addElement.Properties.Item("requireAccess").Value = "Script"
Call handlersCollection.AddElement(addElement, 0)

adminManager.CommitChanges()