简体   繁体   English

长时间运行的php / fastcgi脚本在IIS 7.5上挂起

[英]Long running php/fastcgi script hangs on IIS 7.5

I have a php application running on IIS 7.5 , php 5.4 running as fastcgi. 我有一个在IIS 7.5上运行的php应用程序,以fastcgi运行的php 5.4。 The application works absolutley fine with the exception that long running php scripts seem to hang; 该应用程序绝对可以正常工作,但长时间运行的php脚本似乎挂起了。 no 500 error they simply seem never complete and return the results to the browser. 没有500错误,它们看起来似乎永远不会完成,并将结果返回到浏览器。

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. 如果我运行脚本超过175秒,它将挂起。 Below that it will return the results to the browser. 在此之下,它将结果返回给浏览器。

Here are the time out parameters that I've set for php and fastcgi. 这是我为php和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? 如果我的推论是错误的,请纠正我,但是可以公平地说,如果脚本超时,浏览器将出现错误,好像脚本在完成之前被IIS杀死,那么什么都不会返回到浏览器,您会得到什么?就浏览器而言看起来像是挂了?

fastcgi 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. 如果长时间运行的脚本无法与浏览器通信,则在180秒左右后,大多数浏览器将对服务器返回结果无响应。 The server script wasn't hanging or being terminated, it was the browsers (ie,ff and chrome) becoming unresponsive. 服务器脚本没有挂起或终止,而是浏览器(即ff和chrome)变得无响应。

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. IIS管理器->选择服务器->选择工作进程(中央窗格)->选择应用程序池->选择查看请求(右侧窗格),并观察状态和经过的时间列。 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. 状态从ExecuterequestHandler更改为Sending response,然后脚本按原样完成,但浏览器仍然看起来像他们在等待服务器响应。

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 所以我按照@Dario在PHP flush中提供的说明将ResponseBufferLimit设置为0, 在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. 这样就解决了问题:)如果此解决方案对您有帮助,请访问上面的问题,并请Dario再给我+1,也许还有一个给OP询问他的问题和脚本。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM