Common Gateway Interface

Also found in: Acronyms, Wikipedia.

common gateway interface

[‚käm·ən ‚gāt‚wā ′in·tər‚fās]
(computer science)
A protocol that allows the secure data transfer to and from a server and a network user by means of a program which resides on the server and handles the transaction. For example, if an intranet user sent a request with a Web browser for database information, a CGI program would execute on the server, retrieve the information from the database, format it in HTML, and send it back to the user. Abbreviated CGI.

Common Gateway Interface

(World-Wide Web)
(CGI) A standard for running external programs from a World-Wide Web HTTP server. CGI specifies how to pass arguments to the program as part of the HTTP request. It also defines a set of environment variables that are made available to the program. The program generates output, typically HTML, which the web server processes and passes back to the browser. Alternatively, the program can request URL redirection. CGI allows the returned output to depend in any arbitrary way on the request.

The CGI program can, for example, access information in a database and format the results as HTML. The program can access any data that a normal application program can, however the facilities available to CGI programs are usually limited for security reasons.

Although CGI programs can be compiled programs, they are more often written in a (semi) interpreted language such as Perl, or as Unix shell scripts, hence the common name "CGI script".

Here is a trivial CGI script written in Perl. (It requires the "CGI" module available from CPAN).

#!/usr/bin/perl use 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 HTML page containing the IP address or hostname of the machine that generated the initial request. If run from a command prompt it outputs:

Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" lang="en-US" xml:lang="en-US"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>CGI Test</h1>Your IP address is: localhost </body> </html>

The CGI program might be saved as the file "" in the appropriate directory on a web server, e.g. "/home/httpd/test".

Accessing the appropriate URL, e.g., would cause the program to run and a custom page produced and returned.

Early web servers required all CGI programs to be installed in one directory called cgi-bin but it is better to keep them with the HTML files to which they relate unless they are truly global to the site. Similarly, it is neither necessary nor desirable for all CGI programs to have the extension ".cgi".

Each CGI request is handled by a new process. If the process fails to terminate for some reason, or if requests are received faster than the server can respond to them, the server may become swamped with processes. In order to improve performance, Netscape devised NSAPI and Microsoft developed the ISAPI standard which allow CGI-like tasks to run as part of the main server process, thus avoiding the overhead of creating a new process to handle each CGI invocation. Other solutions include mod_perl and FastCGI.

Latest version: CGI/1.1.
References in periodicals archive ?
4, which now provides support for any third-party Web server that supports the Common Gateway Interface (CGI) or FastCGI protocol mechanism.
the Win32 perl 5 package pre-installed for Common Gateway Interface (CGI) and API use, plus software development kit;
By accessing information at this level, ArrowPoint's Web switches can reliably bypass caches for non-cacheable content such as Common Gateway Interface (CGI), Active Server Pages (ASP), or database queries, and transmit these non-cacheable requests directly to the origin server.
WebBoard, with a suggested list price of $249, enables webmasters to add online conferencing to any Windows web server that fully supports the Windows Common Gateway Interface (Win-CGI), including O'Reilly's own award-winning server WebSite.
Since being introduced in 1996, PeriProducer, Periphonics' graphical application development tool, and PeriWeb have enabled application specialists to build applications without the need for C programming or Common Gateway Interface development.
ISAPI enables Web application developers to bypass the coding procedures required by the widely-used Common Gateway Interface (CGI) standard," said Philip Denzer, president and CEO of Process.
Authorization Server delivers this protection without requiring any changes to applications, such as Web pages and applets, server-side Common Gateway Interface (CGI), and Java(TM) based programs and back-end applications.
Standards and tools, such as, Common Gateway Interface ("CGI"), need to be eclipsed by new, efficient software development strategies and tools.
The Cheetah Web Server's optimized support for the Common Gateway Interface (CGI) guarantees low overhead operation.
development, and the Common Gateway Interface (CGI) 1.
The initial site is being finished utilizing state of the art common gateway interface (CGI) scripting technology, retrieving real-time data from a SQL server database using Active Server Pages (ASP) developed by Microsoft (NASDAQ:MSFT).
Built around industry standards, like Open Database Connectivity (ODBC) and the Common Gateway Interface (CGI), WebDBC is compatible with a wide variety of SQL databases and Web tools.