Cherokee Web Server: FastCGI

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:

Each Server parameter accepts these sub-parameters:

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.