Common Gateway Interface
Encyclopedia : C : CO : COM : Common Gateway Interface
The Common Gateway Interface (CGI) is a standard protocol for interfacing external application software with an information server, commonly a web server. This allows the server to pass requests from a client web browser to the external application. The web server can then return the output from the application to the web browser.
CGI arose out of discussions on the www-talk mailing list between Rob McCool, John Franks, Ari Luotonen, George Phillips and Tony Sanders in 1993. Rob McCool, working at NCSA, drafted the initial specification and provided a reference implementation in the NCSA HTTPd web server using environment variables to store parameters passed from the web server execution environment before spawning the CGI program as a separate process.
An example of a CGI program is the one implementing a wiki. The user agent requests the name of an entry; the server will retrieve the source of that entry's page (if one exists), transform it into HTML, and send the result back to the browser or prompt the user to create it. All wiki operations are managed by this one program.
The way CGI works from the Web server's point of view is that certain locations (e.g.
Because this technology generally requires a fresh copy of the program to be executed for every CGI request, the workload could quickly overwhelm web servers, inspiring more efficient technologies such as mod_perl or ASP that allow script interpreters to be integrated directly into web servers as modules, thus avoiding the overhead of repeatedly loading and initializing language interpreters. However, this is only applicable for so-called high level languages that needs interpreters. Such overloads can be avoided by utilizing languages like C. By using C or similar compiled languages it is possible to reach higher efficiency levels, because such programs terminate their execution cycle faster than interpreted languages with less operating system overload.
Workarounds for scripting languages
The overhead of spawning new processes to compile the server code can be easily handled if the code is occasionally changed. One example is FastCGI while others include programming accelerators that take a web script when initially called and store a compiled version of the script in system location so that further requests for the file are automatically directed to the compiled code instead of invoking the script interpreter every time the script is called. When scripts are changed the temporary accelerator cache can be emptied to ensure that the new script is called instead of the old one.
Thus for languages such as C or Pascal, which are usually compiled anyway, CGI programs are no different from other programs in this regard, and require no special processing.
Another approach used for scripting languages is to embed the interpreter directly into the web server so that it can be executed without creating a new process. The Apache web server has a number of modules such as mod_perl, mod_php, mod_python, mod_ruby, and mod_mono which do this.
See also
References
- [Common Gateway Interface: Introduction]. Retrieved March 18, 2006.
External links
- The [CGI standard] at w3.org.
- The [CGI/1.1 specification].
- The complete list of CGI variables is at http://hoohoo.ncsa.uiuc.edu/cgi/env.html.
- The [SCGI] protocol is a replacement for the Common Gateway Interface (CGI) protocol.
- [Python CGI Scripts] - A set of CGI applications and modules for CGI programming with the Python language.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
