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. http://www.example.com/wiki.cgi) are defined to be served by a CGI program. Whenever a request to a matching URL is received, the corresponding program is called, with any data that the client sent as input. Output from the program is collected by the Web server, augmented with appropriate headers, and sent back to the client.
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 PHP 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 high-level languages that need 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 overhead. Even better, RPG programs on the IBM iSeries/AS400 may stay resident in memory with databases already open, allowing for faster execution on subsequent usage. The optimal configuration for any web application will obviously depend on application-specific details, amount of traffic, and complexity of the transaction; a software engineer analyzes these tradeoffs to determine the best implementation for a given task and budget.
|