长时间运行的php / fastcgi脚本在IIS 7.5上挂起 [英] Long running php/fastcgi script hangs on IIS 7.5

查看:182
本文介绍了长时间运行的php / fastcgi脚本在IIS 7.5上挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在IIS 7.5上的php应用程序,php 5.4作为fastcgi运行。应用程序工作absolutley罚款,除了长期运行的PHP脚本似乎挂起;没有500错误,他们似乎永远不会完成并将结果返回给浏览器。

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.

我在下面编写了一个简单的测试脚本,以消除主要编程错误的可能性app:

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;
    }
}

?>

如果我将脚本运行超过175秒,它就会挂起。下面它会将结果返回给浏览器。

If I run the script beyond 175 seconds it hangs. Below that it will return the results to the browser.

以下是我为php和fastcgi设置的超时参数。为了得到各种各样的超时错误,我也玩过这些非常低的设置并且成功了,这让我得出结论,我错过了另一种设置......也许。

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.

如果我的假设是错误的,请纠正我,但是如果脚本超时浏览器会出现错误,如果脚本在完成之前被IIS杀掉,则没有任何内容返回给浏览器就浏览器而言,你会看到一个挂起的东西?

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


推荐答案

如果长时间运行的脚本无法与浏览器通信,180秒左右后,大多数浏览器将无法响应返回结果的服务器。服务器脚本没有挂起或被终止,浏览器(即ff和chrome)没有响应。

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.

要检查这一点,我运行了我的脚本并观看了请求的状态。
IIS管理器 - >选择服务器 - >选择工作进程(中央窗格) - >选择应用程序池 - >选择查看请求(右侧窗格)并查看已过时的状态和时间列。您将不得不反复单击全部显示以查看值更新。

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.

状态从ExecuterequestHandler更改为发送响应,然后脚本完成,但应该完成仍然看起来他们正在等待服务器响应。

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.

下一步,我查看了服务器上的响应缓冲。设置设置为非常高的数字,意味着冲洗不起作用。所以我按照@Dario在 PHP flush停止时提供的说明将ResponseBufferLimit设置为0在IIS7.5中刷新

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另外一个+1请,或者可能是他的问题和脚本的OP。

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.

谢谢

这篇关于长时间运行的php / fastcgi脚本在IIS 7.5上挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆