Long running php/fastcgi script hangs on IIS 7.5

淺唱寂寞╮ 提交于 2019-12-08 19:08:28
Rich

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!