mod_fcgid从管道读取超时,在头文件之前的脚本输出结束,多个版本的PHP


mod_fcgid read timeout from pipe, end of script output before headers, multiple versions of PHP

我在Windows上使用mod_fcgid在Apache下设置了几个版本的PHP。配置如下:

LoadModule fcgid_module modules/mod_fcgid.so
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "c:/php/tmp"
FcgidInitialEnv TMP "c:/php/tmp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 600
FcgidConnectTimeout 600
FcgidProcessLifeTime 3600
FcgidMaxRequestsPerProcess 900 
FcgidMaxProcesses 10
FcgidMaxRequestLen 80131072
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

然后在每个vhost指令中指定fcgi处理程序:

<Virtualhost *:80>
    VirtualDocumentRoot "e:/hosts/example"
    ServerName example.local
    # location of php.ini
    FcgidCmdOptions c:/php/php5.5.12/php-cgi.exe InitialEnv PHPRC="c:/php/php5.5.12/"
    FcgidWrapper "c:/php/php5.5.12/php-cgi.exe" .php
</Virtualhost>
<Virtualhost *:81>
    VirtualDocumentRoot "e:/hosts/example"
    ServerName example.local
    # location of php.ini
    FcgidCmdOptions c:/php/php7.0.12/php-cgi.exe InitialEnv PHPRC="c:/php/php5.5.12/"
    FcgidWrapper "c:/php/php7.0.12/php-cgi.exe" .php
</Virtualhost>

这种方式http://example.local/适用于PHP 5.5,但http://example.local:81/提供相同的代码,但使用PHP 7.0。非常方便在同一系统上测试多个版本的PHP。

但是我总是在大约40-60秒后得到fcgi超时,这使我无法有效地使用xdebug。

我在SO上检查了一些类似的问题,其中大多数正确建议设置更高的FcgidIOTimeout选项值,但由于未知的原因,这对我的系统绝对没有影响。

我在回答我自己的问题,希望这能节省一些人的时间来解决这个问题。

花了很多时间在这上面,我发现罪魁祸首是在vhost配置中使用 FcgidCmdOptions 。如果定义了全局fcgid选项,则忽略!因此,我必须在FcgidCmdOptions中设置IOTimeout选项,而不是设置FcgidIOTimeout

最终配置如下:

<Virtualhost *:80>
    VirtualDocumentRoot "e:/hosts/example"
    ServerName example.local
    FcgidCmdOptions c:php/php5.5.12/php-cgi.exe '
            InitialEnv PHPRC="c:php/php5.5.12/" '
            InitialEnv PHP_FCGI_MAX_REQUESTS=1000 '
            IOTimeout 3600 '
            ConnectTimeout 3600 '
            MaxProcessLifeTime 7200 '
            IdleTimeout 3600 '
            MaxRequestsPerProcess 900
    FcgidWrapper "c:php/php5.5.12/php-cgi.exe" .php
</Virtualhost>
<Virtualhost *:81>
    VirtualDocumentRoot "e:/hosts/example"
    ServerName example.local
    FcgidCmdOptions c:php/php7.0.12/php7-cgi.exe'
            InitialEnv PHPRC="c:php/php7.0.12/" '
            InitialEnv PHP_FCGI_MAX_REQUESTS=1000 '
            IOTimeout 3600 '
            ConnectTimeout 3600 '
            MaxProcessLifeTime 7200 '
            IdleTimeout 3600 '
            MaxRequestsPerProcess 900
    FcgidWrapper "c:php/php7.0.12/php7-cgi.exe" .php
</Virtualhost>