# FastCGI

The fcgi handler queries to [FastCGI] servers, such as PHP, in order to execute scripts. It is basically the same thing as CGI but much faster.

## Parameters

This module accepts one parameter, and at the same time, supports all the CGI handler parameters:

- Server path or hostname:port: It defines a server entry

Each Server parameter accepts these sub-parameters:

- Interpreter "path": Defines the command line of the interpreter for this server. This sub-parameter only available for FastCGI servers which are running in the same computer with the webserver. The webserver will try to run the command line if it fails to connect to the specified address in Server parameter. If you run the FastCGI servers manually, this sub-parameter is not needed.
- Env variable_name "value": Set an environment variable for the FastCGI servers.

If multiple Server entries defined, the requests will be round-robinly served by each of Server entry.

## Examples

This example shows a typical usage of FastCGI. It connects to a FastCGI server located in localhost in port 8002. If no server is running, the webserver will run the FastCGI server by issuing command defined in Interpreter sub-parameter.

    Extension php {
       Handler fcgi {
          Server localhost:8002 {
             Env PHP_FCGI_MAX_REQUESTS "-1"
             Env PHP_FCGI_CHILDREN     "5"
             Interpreter  "/usr/bin/php5-fastcgi -b 8002"
          }
       }
    }

This example shows a typical usage of multiple FastCGI servers. It connects to a FastCGI servers located in several locations. If no server is running in the local computer, the webserver will run the FastCGI server by issuing command defined in Interpreter sub-parameter. Note that for remote FastCGI servers, you are responsible to run the FastCGI servers there manually.

    Extension php {
       Handler fcgi {
          Server localhost:8002 {
             Env PHP_FCGI_MAX_REQUESTS "-1"
             Env PHP_FCGI_CHILDREN     "5"
             Interpreter  "/usr/bin/php5-fastcgi -b 8002"
          }
          Server 192.168.0.13:8002 {
             Env PHP_FCGI_MAX_REQUESTS "-1"
             Env PHP_FCGI_CHILDREN     "5"
          }
          Server 192.168.0.10:8002 {
             Env PHP_FCGI_MAX_REQUESTS "-1"
             Env PHP_FCGI_CHILDREN     "5"
          }
       }
    }

## Note

The PHP_FCGI_CHILDREN environment variable is mandatory for PHP FastCGI servers. It define how much children should serve the requests coming from the webserver. If you define PHP_FCGI_MAX_REQUESTS, the value should be negative so that PHP would take the request as much as possible. If you left it unset, PHP will take the default value (500) and your 500th request will be rejected and FCGI handler will spew Error 500 (Internal server error) for it.