Configure PHP Process Recycling Behavior

by Tali Smith


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.

    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.

    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.

    Figure 3: Edit FastCGI Application dialog box

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


    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).

    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'