I have a php application running on IIS 7.5 , php 5.4 running as fastcgi. The application works absolutley fine with the exception that long running php scripts seem to hang; no 500 error they simply seem never complete and return the results to the browser.
I've written a simple test script below to eliminate the possibility of programming error in the main app :
<?php
/* test timeout */
/*set_time_limit(110);*/
echo "Testing time out in seconds\n";
for ($i = 0; $i < 175; $i++) {
echo $i." -- ";
if(sleep(1)!=0)
{
echo "sleep failed script terminating";
break;
}
}
?>
If I run the script beyond 175 seconds it hangs. Below that it will return the results to the browser.
Here are the time out parameters that I've set for php and fastcgi. I've also played around setting these really low in order to get various time out errors and have succeeded which brings me to the conclusion that there's another setting that I'm missing .. perhaps.
Correct me if my presumptions are wrong but would it be fair to say that if a script times out the browser will get an error where as if a script is killed off by IIS before completion then nothing is returned to the browser and you get a what looks like a hang as far as the browser is concerned?
fastcgi
activity timeout=800 Idle Timeout = 900 request Timeout 800
Php
max_execution_time=700
If a long running script doesn't communicate with the browser , after 180 seconds or so most browsers will become unresponsive to the server returning the results. The server script wasn't hanging or being terminated, it was the browsers (ie,ff and chrome) becoming unresponsive.
To check this , I ran my script and watched the status of the request.
IIS manager-> select the server-> select worker processes(central pane)->select the application pool-> select view requests (right hand pane) and watched the status and time elapsed columns. You will have to repeatedly click "show all" to see the values updating.
The state changed from ExecuterequestHandler to Sending response and then the script finished as it should but the browsers still looked like they were waiting for the server to respond.
I updated my test script from the above to this to ensure the browsers were being fed responses regularly:
<?php
@ini_set("output_buffering", "Off");
@ini_set('implicit_flush', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('max_execution_time', 800);
header( 'Content-type: text/html; charset=utf-8' );
echo "Testing time out in seconds\n";
for ($i = 0; $i < 600; $i++) {
echo $i." -- ";
if(sleep(1)!=0)
{
echo "sleep failed script terminating";
break;
}
flush();
ob_flush();
}
?>
The output was't coming back to the browsers bit buy bit as it should and the problem remained.
Next step , I looked at response buffering on the server. The setting was set to a very high number and meant that flushing wouldn't work. So I set ResponseBufferLimit to 0 as per the instructions provided by @Dario in PHP flush stopped flushing in IIS7.5
This solved the problem :) If this solution has helped you please visit the above question and give Dario another +1 from me please, and maybe one to the OP for his question and script.
Thanks