What is Common Gateway Interface (CGI)?
Common Gateway Interface (CGI) in the context of web development is an interface for executing executable files via a web server. In most cases this means passing an HTTP request to an application to return a dynamically generated HTML page to a browser. While almost any program that can be run on a web server can be used as a CGI script, Perl is the most popular language.
The standard for CGI is defined in RFC 3875.
In the early days of web development, CGI was one of the few ways to provide interactivity in a web application. It was most common on Apache, but ports were made to run CGI on IIS as well.
The most common use of CGI is to use scripting languages. Hence it is often referred to as a CGI script. CGI programs and scripts are usually collected in a folder called / cgi-bin /.
The main disadvantage of CGI is that each page load creates overhead in loading the programs into memory. Data cannot simply be cached between page loads. Because of this drawback, many developers have moved to application servers that are still running. However, there is a large code base in existence, much of which is included in Perl. Proponents of CGI argue that it is simple, stable, and a good choice for certain uses, especially tasks where Perl excels, such as word processing. Workarounds also avoid loading in the Perl or PHP runtime for each request by including the runtime on the web server (mod_perl and mod_php in Apache) or other solutions like FastCGI (separate processes that handle multiple requests).