Common Gateway Interface

Common Gateway Interface (CGI) is a protocol by which a web server uses a local executable program to handle a request from a web browser.

CGI uses a convenient, if somewhat crude, kind of inter-process communication. For each suitable request it receives, the web server runs a new instance of the CGI handler program. It pipes the body of the request, if any, to the program's standard input stream. All other parameters are communicated via environment variables.

The CGI handler writes its response to its standard output stream, which is read by the web server, and relayed over the network to the web browser.

A file with a .cgi extension might be a CGI handler program (though there are no restrictions on the name of a CGI handler program, other than those imposed by the operating system). If so, it will use a standard executable or scripting file format (such as Perl), not some hypothetical "CGI file format". A .cgi file could also be the saved response from a CGI handler, in which case the most likely format is HTML (though there are no restrictions on the file format of a CGI response).

FastCGI
A variant named FastCGI allows a single process to handle multiple requests. Some other method of inter-process communication is used, such as a Unix domain socket.

Links

 * RFC 3875: The Common Gateway Interface (CGI) Version 1.1
 * Common Gateway Interface
 * FastCGI