Common Gateway Interface
common gateway interface
[‚käm·ən ‚gāt‚wā ′in·tər‚fās]Common Gateway Interface
(World-Wide Web)The CGI program can, for example, access information in adatabase and format the results as HTML. The program canaccess any data that a normal application program can, howeverthe facilities available to CGI programs are usually limitedfor security reasons.
Although CGI programs can be compiled programs, they are moreoften written in a (semi) interpreted language such asPerl, or as Unix shell scripts, hence the common name"CGI script".
Here is a trivial CGI script written in Perl. (It requiresthe "CGI" module available from CPAN).
#!/usr/bin/perluse CGI qw(:standard);
print header, start_html,h1("CGI Test"),"Your IP address is: ", remote_host(),end_html;
When run it produces an HTTP header and then a simple HTMLpage containing the IP address or hostname of the machinethat generated the initial request. If run from a commandprompt it outputs:
Content-Type: text/html; charset=ISO-8859-1
-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
CGI Test
Your IP address is: localhostThe CGI program might be saved as the file "test.pl" in theappropriate directory on a web server,e.g. "/home/httpd/test".
Accessing the appropriate URL, e.g.http://acme.com/test/test.pl, would cause the program torun and a custom page produced and returned.
Early web servers required all CGI programs to be installed inone directory called cgi-bin but it is better to keep themwith the HTML files to which they relate unless they are trulyglobal to the site. Similarly, it is neither necessary nordesirable for all CGI programs to have the extension ".cgi".
Each CGI request is handled by a new process. If the processfails to terminate for some reason, or if requests arereceived faster than the server can respond to them, theserver may become swamped with processes. In order to improveperformance, Netscape devised NSAPI and Microsoftdeveloped the ISAPI standard which allow CGI-like tasks torun as part of the main server process, thus avoiding theoverhead of creating a new process to handle each CGIinvocation. Other solutions include mod_perl and FastCGI.
Latest version: CGI/1.1.
http://hoohoo.ncsa.uiuc.edu/cgi.