| CGI
Definition
CGI stands for Common Gateway Interface
and is a standard for running external programs
from a web server. CGI specifies how to
pass arguments to the executing program
as part of the HTTP request. In addition,
it defines a set of environment variables.
Normally, each program is created in order
to dynamically generate HTML which is then
passed back to the browser, but it can also
do a variety of server-side tasks, such
as redirects, reading of and writing to
text files, etc.
In order to improve performance, Netscape
and Microsoft devised, respectively, the
NSAPI and ISAPI standards 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.
What It Really Is
More than anything, CGI is a framework.
It isn’t a language at all. In fact,
languages are written for use within CGI
— saved as CGI extensions and run
by the CGI interpreter on the server. The
most common language used is Perl, and others
include C/C++, Fortran, TCL, Visual Basic,
and AppleScript. CGI is extremely powerful
in that it can be both compiled (when written
using languages like C++) or interpreted
(using languages like Perl and TCL). More
often than not, CGI scripts and applications
are written in Perl. In fact, the use of
Perl is so commonplace as the language for
writing CGI scripts that most people think
they are one and the same.
CGI was developed for Unix systems in the
1980s and is still on version 1.1. Unlike
other software, this is, in fact, a good
thing, since CGI was designed with a specific
goal in mind, and that goal hasn’t
changed over time.
Advantages
+ Ability to write in a multitude of
languages
+ Speed and efficiency
+ Powerful and robust nature
+ Ability to compile or interpret as appropriate
+ Cross platform compatibility
Disadvantages
+ Steeper learning curve than newer
technologies
+ Decrease in available resources associated
with becoming more and more “old
school”
+ Slower running speed as opposed to newer
technologies
Examples
For a multitude of examples of CGI usage,
as well as a full manual, go to hoohoo.ncsa.uiuc.edu/cgi.
Here are some standard types of things you
might find.
Displaying
Date & Time
($theday, $themonth, $thedate, $thetime,
$thezone, $theyear) = split(' ', `date`);
print "It's $thetime $thezone on
$theday $themonth $thedate, $theyear.";
|
| Showing
a Random Word
@words_list = ('Hammer', 'in', 'those',
'screws.');
$random_word = $words_list[rand(@words_list)];
print "<CENTER>$random_word</CENTER>";
|
Similar Technologies
CGI has similar technologies on two fronts.
There are other “container technologies,”
along with Unix-based cross-platform technologies.
+ PHP: Just like CGI, PHP is cross-platform
compatible. It is a very strong language
with an incredibly large and supportive
community.
+ ASP: ASP is similar to CGI in that it
is also a “container technology.”
ASP pages can be written in several languages,
including VBScript and Jscript (the server-side
version of JavaScript).
|