I hear a lot about the problem where web server (IIS) throws an error saying that PHP script has timed out in our forums. Let’s try to understand the reason behind this. I will be using a Windows 7 Enterprise machine (having IIS 7.5) to explain this but this should be applicable to Windows 2008/Windows Vista too. The same can be told true for Windows 2003/Windows XP with some difference like IIS stores FastCGI configuration in fcgiext.ini file rather than application meta-base. However the concept should be exactly similar.
Let me now summarize some of the IIS FastCGI settings and PHP INI configuration directive to ensure that everyone is on the same page and which are most important for this discussion.
Two important FastCGI settings:
Important PHP INI directive for this discussion:
All the above three impacts your script execution time. Ideally you will have the value of RequestTimeout greater than or equal to ActivityTimeout. Well this is not a hard rule but going by meaning of these two timeouts it makes sense to do this. Assume you are uploading a file of size ‘X’ MB and it takes 500 second to upload it (assuming PHP is configured properly to allow upload of files and so the size of ‘X’ MB is also allowed) and you have below value for the two timeouts:
ActivityTimeout=501
RequestTimeout=400
This configuration will result into request timeout while uploading the file. The reason is that though an I/O operation (in this case file upload) is allowed for 501 seconds which is perfectly fine for this case, request time out is less than 501 (and is at 400) and so FastCGI will encounter a request timeout. Remember this will be done by the web server (IIS here) and not PHP. So setting the value of RequestTimeout higher than ActivityTimeout makes more sense.
However assume your max_execution_time is set to 300 seconds and you are running a PHP script which executes for time more than 300 seconds and FastCGI timeout settings are same as above. This time PHP will terminate itself.
This implies that (assuming you have RequestTimeout set to a value higher than ActivityTimeout) you script will run maximum for time in seconds which is configured for max_execution_time or RequestTimeout whichever is less.
This should help you configuring the PHP script to run for a longer period of time.
Some Frequently asked question
- I am changing the fastcgi.ini file or php.ini file but settings are not getting effected on XP/2k3 or I am changing applicationhost.config or php.ini on a IIS7 machine and changes are not getting effected.
Please recycle the application pool or restart the server to make the FastCGI/PHP process read the new settings. If you are using latest FastCGI and you do not want to restart the application and want changes to be picked up on it’s own you can as well use the feature called ‘Monitor Changes to File’. Details about this can be found at [blogs.iis.net] for IIS7.5 and at [learn.iis.net] for IIS6.0. For information regarding if this feature is supported on your configuration or not please refer to blog post at "/>
Truncated by Planet PHP, read more at the original (another 7922 bytes)