CGI OverviewThe Common Gateway Interface (CGI) is the platform-independent standard for adding form support to Web servers. While CGI is capable of doing much more (such as building custom web pages on the fly), form handling is its primary use.
CGI was designed based on the fact that most operating systems can execute interpretive scripts, and that those scripts can interact with the operating system's environment variables and standard input and output (stdio) mechanisms. Special exceptions are made for systems like MacOS.
CGI uses standard input (stdin) to pass form requests to form handler; environment variables are used to pass certain HTTP-related information to the handler; standard output (stdout) is used by the form handler to return a response back to the requesting Web browser.
Scripting LanguagesMost operating systems support some sort of simple, command-based scripting language. DOS supports BATch file scripts, NT support CMD scripts and unix supports various forms of c, bourne, korn shell scripts. All are relatively simple for most people to create and modify. Most CGI implementations support native shell scripting.
However, most of these shell scripts are limited in capability or not readily available on major platforms. One scripting language became an early favorite for CGI use: PERL.
PERL is available on most platforms, is c-like, and comes with extensive system support, socket, math, memory and string handling capabilities. Many CGI form handlers are written in PERL.
While both TCL and Python have some advantages over PERL, they have not gained wide acceptance as standard CGI languages. Java has gained wide acceptance, but it's not as simple for most people to learn, and requires compilation -- which complicates remote administration on some operating systems.
As a result, there will continue to be a need for something like PERL for maintaining "quick and dirty" form handlers.
PERL Form Handler ExampleHere is the HTML source for the following CGI form:
Drawbacks to PERLThe major drawback to most PERL implementations is that PERL scripts need to be loaded into memory and interpretted each time they are run, which creates a serious load on Web servers.
Server-side Java handlers ease the load by being pre-tokenized. This, combined with Java's multi-threading, object-orientedness, rich class library and portability make it an increasingly popular replacement for PERL.
While compiled binary executables are non-portable, they are also becoming increasingly popular, as they generally load and run much faster than Java applets.
On NT, the Internet Server API (ISAPI) is becoming a very popular substitute for CGI. Instead of using environment variables and stdio, ISAPI uses direct memory variables and accesses TCP sockets directly. Instead of being interpretted, they are precompiled. Instead of being loaded each time they are called, they can be pre-loaded in memory as Dynamic Link Libraries (DLLs) and used "in-process".
SummaryWhile many Web administrators and content creators are relying increasingly on server-side Java and ISAPI, the ease of remote maintainance of PERL keeps it a serious contender for handling CGI forms.