phpapachemod-fastcgi

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


I've set up several version of PHP under Apache on Windows using mod_fcgid. The configuration is like this:

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

And then a specific fcgi handler in each vhost directive:

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

This way http://example.local/ works with PHP 5.5, but http://example.local:81/ serves the same code but with PHP 7.0. Very convenient for testing multiple versions of PHP on the same system.

But I keep getting fcgi timeouts after about 40-60 seconds, which prevents me from using xdebug effectively.

I have checked number of similar questions on SO, most of which correctly suggest to set higher value of FcgidIOTimeout option, but for unknown reason this has absolutely no effect on my system.


Solution

  • I'm answering my own question hoping this will save someone hours of fighting with this problem.

    Having spent quite a lot of time on this, I've figured our that the culprit was in using FcgidCmdOptions in vhost configuration. If it's defined, global fcgid options are simply ignored! So, instead of setting FcgidIOTimeout I had to set IOTimeout option in FcgidCmdOptions.

    The final configuration is the following:

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