FastCGI

FastCGI is a standard for the integration of external software to generate dynamic web pages in a web server. FastCGI is similar to the Common Gateway Interface (CGI), but was designed to circumvent performance issues.

Unlike CGI

When calling a CGI -based website, a process of the CGI program is started and ended back at the end of the request from the web server. Because CGI programs are often written in a scripting language such as Perl, this means that for each page view of the often quite extensive interpreter must be loaded, resulting in a large overhead means ( loading the interpreter takes longer than the actual program execution with simple CGI programs ). In addition, each request needs its own interpreter, ie, with multiple parallel requests are in accordance with several copies of the interpreter in the server's memory. CGI has indeed found its simplicity, independence from the programming language and far-reaching support from virtually all Web servers a very wide distribution, but the mentioned overhead results in high latency and heavily loaded servers quickly to overloading.

In contrast, in FastCGI program to run (including interpreter, if necessary) loaded only once and is then available for multiple requests available - whether from the same client or different clients. The communication with the server takes place not through environment variables and Standardein-/ausgabe but via Unix domain sockets or TCP network connections, that is, the program can even run on another computer.

Programmatically, can be the difference to CGI programs fix the fact that a FastCGI program has a central loop that accepts requests and may well run as long as the Web server:

Use FCGI;   $ var = ' foo';   while ( FCGI :: accept () > = 0) {     Edit ... http request ...   } During the passage of this loop variables are retained in memory, which on one hand further possibilities for optimization over CGI programs allow, on the other hand, a more careful programming to avoid memory leaks ( memory leaks ).

Operation

The communication with the web server is packet -oriented and connectionless. A data packet contains the header the FastCGI protocol version, message type, a request ID and the length of the following data. The message type corresponds largely known from CGI data sources - a packet can, inter alia, the CGI environment variable, the contents of the standard input ( POST ) or stdout transport (for the output to the client ). Multiple clients can be served simultaneously as they can be distinguished based on the request ID; therefore, in contrast to only a CGI program instance is needed to serve many clients.

326996
de