Configure PHP Process Recycling Behavior

by Tali Smith

Introduction

Make sure that FastCGI always recycles the php-cgi.exe processes before the native PHP recycling kicks in. The FastCGI process recycling behavior is controlled by the configuration property instanceMaxRequests. This property specifies how many requests the FastCGI process will process before recycling. PHP also has a similar process recycling functionality that is controlled by an environment variable PHP_FCGI_MAX_REQUESTS. By setting instanceMaxRequests to be smaller or equal to PHP_FCGI_MAX_REQUESTS, you can ensure that the native PHP process recycling logic will never kick in.

The FastCGI settings can be configured either by using IIS Manager or by using the command-line tool AppCmd.

Use the IIS Manager

  1. To configure FastCGI recycling settings by using IIS Manager, you must install Administration Pack for IIS 7.0 and above, and then select FastCGI Settings at the server level.

    Screenshot of I I S Manager window with application icons displayed in features view.
    Figure 1: IIS Manager, FastCGI Settings

  2. Next, select the FastCGI application that you want to configure, and then click Edit in the Actions pane on the right side.

    Screenshot of I I S Manager window with Fast C G I Settings tab displayed.
    Figure 2: FastCGI Settings page

  3. In the Edit FastCGI Application dialog box, set InstanceMaxRequest to 10000, and then click on the browse button next to the EnvironmentVariables setting.

    Screenshot of Edit Fast C G I Application dialog box with Enviornment Variables setting highlighted.
    Figure 3: Edit FastCGI Application dialog box

  4. Add the PHP_FCGI_MAX_REQUESTS environment variable, and set its value to 10000.

    Note

    If you do not configure these settings, then the following default settings are used: InstanceMaxRequests of 200, PHP_FCGI_MAX_REQUESTS of 500 (on most PHP builds).

    Screenshot of the Environment Variables Collection Editor dialog box. The P H P F  F C G I Max Requests setting and value are highlighted.
    Figure 4: Environment Variables Collection Editor dialog box

Use the Command Line

To configure the recycling behavior of FastCGI and PHP via appcmd, use the following commands:

C:\>%windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='c:\{php_folder}\php-cgi.exe'].instanceMaxRequests:10000
C:\>%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\{php_folder}\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS'