Date Initially Written: 8 January 2003.
Problem: When running a PHP script with IIS a CGI Timeout
error occurs after 5 minutes.
Operating System: Windows 2000 Professional with service pack 3, IIS 5.0.
Background: The PHP script I was running takes a long time to complete as it was checking and verifying that a large number of web pages exist. It could take an hour or more to complete.
Resolution Steps: I first tried setting the script's time limit with the following PHP code:
set_time_limit(10800); // Three hour timeout
But this didn't help. It seemed to me that IIS was killing the script after 5 minutes. I looked in the IIS management console (Start Settings Control Panel Administrative Tools Internet Services Manager) but couldn't find anything related to the CGI timeout period.
Searching Google Groups I found several people that had this problem but no helpful solutions. One particular MVP (Microsoft Most Valued Professional) insisted that it was impossible for a script to run for more than 5 minutes and said:
you just can't run stuff across http that takes longer than five minutes to run. get over it.
I knew this wasn't true as I'd run long executing PHP scripts under Apache before. After much more digging around I finally found where the CGI Timeout was specified. This is how you change it:
iisreset
The above instructions work for IIS 5.0, which ships with Windows 2000. If you have Windows XP then you've probably got IIS 5.1 and should follow these instuctions:
If you are running Windows Server 2003 then you are running IIS 6.0. Microsoft decided to remove the option to configure the CGI timeout value in IIS 6.0 from the GUI interface. See this article for information on how to set the timeout value in IIS 6 / 7 / 7.5.
Recommended Reading For PHP Programmers: Programming PHP