PHP 脚本在 IIS 上 15 分钟后挂起


PHP script hanging after 15 minutes on IIS

我有一个长时间运行的PHP脚本,运行在IIS(IISEXpress通过WebMatrix 3安装)。

在前 15 分钟内,它工作正常,查询亚马逊产品广告 API,一次一行将输出刷新到浏览器以显示其进度。然后它停止显示任何进度。

我相当确定问题不在于脚本或 Amazon API,因为它每次都达到不同的进度点,但总是在正好 15 分钟停止(我在脚本中内置了一个时间,并且经过的时间刷新到浏览器中的页面)。

为了防止脚本在 30 秒后因错误而中止,我设置了:

set_time_limit(36000); in the script

我听说 IIS 可能在 15 分钟后出现 CGI 超时,并尝试将 CGI 行添加到 ApplicationHostConfig 以覆盖任何默认超时。没有效果。

   <location path="myAmazonScript">
        <system.webServer>
            <cgi createCGIWithNewConsole="true" createProcessAsUser="false" timeout="00:20:00" />
            <handlers>
                <remove name="PHP54_via_FastCGI" />
                <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:'Program Files (x86)'iis express'PHP'v5.4'php-cgi.exe" responseBufferLimit="0" resourceType="Either" />
            </handlers>
        </system.webServer>

(如果您想知道,我将 ResponseBufferLimit 设置为 0 以强制刷新。

在system.webserver部分的其他地方,我们有:

<cgi />
<fastCgi>
    <application fullPath="C:'Program Files (x86)'iis express'PHP'v5.4'php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="600" requestTimeout="600" instanceMaxRequests="10000">
        <environmentVariables>
            <environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
            <environmentVariable name="PHPRC" value="C:'Program Files (x86)'iis express'PHP'v5.4" />
        </environmentVariables>
    </application>
</fastCgi>

不存在其他"超时"值。

顺便说一句,我无法通过GUI运行appcmd或访问IIS设置,大概是因为是IISExpress。但是applicationhost.config似乎工作正常。

任何建议非常感谢。

乔纳森

服务器上的IIS管理器允许您管理FastCGI设置。活动超时 (600) 和空闲超时 (300) 的默认值加起来正好为 15 分钟。

我给每个人加了一个零,我的50分钟脚本就像一个魅力一样通过。