Increase fastCgi / PHP activityTimeout in IIS7
daniel posted this on Jan 8th 2012 at 9:35 pm under Howto, Windows
When your have installed PHP with the Microsoft web platform installer PHP is installed in C:\Program Files (x86)\PHP\v5.2.
When your PHP script runs longer than 10 minutes (600 seconds) you will get an 500 Internal server error.
To fix this issue you will need to increase the fastCgi activityTimeout in IIS7.
After Googling around i found a solutions, but because the web platform installer installs PHP in a path with spaces in it all examples failed.
I Googled some more and after a while i combined 2 solutions and got it to work.
Start a command promt and go to this folder:
c:\Windows\System32\inetsrv
Execute this command to see the current settings:
C:\Windows\System32\inetsrv>appcmd list config -section:system.webServer/fastCgi
Output will be something like this:
<system.webServer>
<fastCgi>
<application fullPath="C:\Program Files (x86)\PHP\v5.2\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="600" requestTimeout="600" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\Program Files (x86)\PHP\v5.2" />
</environmentVariables>
</application>
</fastCgi>
</system.webServer>
To change the timeout to 1 hour (3600 seconds) execute the following command:
C:\Windows\System32\inetsrv>appcmd set config -section:system.webServer/fastCgi "-[fullPath='C:\Program Files (x86)\PHP\v5.2\php-cgi.exe'].activityTimeout:3600"
Not the use of double and single quotes to specify the correct parameters.
After you run this command you will see this output:
Applied configuration changes to section "system.webServer/fastCgi" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"
After running the list config command again the output now looks like this:
<system.webServer>
<fastCgi>
<application fullPath="C:\Program Files (x86)\PHP\v5.2\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="3600" requestTimeout="600" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\Program Files (x86)\PHP\v5.2" />
</environmentVariables>
</application>
</fastCgi>
</system.webServer>
As you can see the activityTimeout is now increased.
Restart your IIS service and your good to go.