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
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 SettingsNext, 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 pageIn 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 boxAdd 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).
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'
Links for Further Information
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for