phpiistimeout

Internal server error 500 after 90 seconds of PHP script running


have a php script that runs for a few minutes. It creates a lot (up to 10000) of small (2-20K) files on the server.

For some reason, after approximately 90 seconds, I always get a 500 Internal Server Error. I thought it might be some php.ini problem, so I edited some values there:

max_execution_time = 1000
max_input_time = 1000
default_socket_timeout = 1000
memory_limit = 400M
post_max_size = 100M
file_uploads = On
upload_max_filesize = 100M

I also checked to see if these new settings occurred by using phpinfo(), and have seen that they did take effect.

What else can I do/change in order to make my script work?

PHP5.5 Windows Server 2008 R2, SP1, Unfortunately, only 600 MB of physical memory Nothing in errors_log.


Solution

  • In hope to save other people's hair (I pulled out pretty much of my own on this one)

    The solution is to increase the FastCGI activity timeout.
    Use appcmd, the IIS 7 command line tool, to modify the IIS configuration XML file.

    Run cmd in an administrator mode.

    To check the current settings use:

    %windir%\system32\inetsrv\appcmd list config -section:system.webServer/fastCgi
    

    To add the activity timeout (assuming CGI location is C:\php\php-cgi.exe):

    %windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='C:\php\php-cgi.exe'].activityTimeout:600
    

    This output now should be similar to this: -

    <system.webServer>
    <fastCgi>
    <application fullPath="C:\PHP\php-cgi.exe" activityTimeout="600" instanceMaxRequests="10000">
    <environmentVariables>
    <environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
    </environmentVariables>
    </application>
    </fastCgi>
    </system.webServer>