|
If you've done any Perl scripting, you're probably familiar with the acronym CGI (Common Gateway Interface). Each word in the acronym Common Gateway Interface helps you to understand the interface:
It's simply a portal for communication between the Webserver and any other program or script that it can access. But CGI is not a programming language! In essence, CGI is a server-side process that serves as a go-between for the Webserver and other applications programs, information resources, and databases. These information resources and databases can reside on the same physical machine as the Webserver or on a machine at some other geographical location. CGI gives you a way to make Websites dynamic and interactive. CGI just makes it possible for a Webserver to pass information (such as what host the user is connecting from, or input the user has supplied through an HTML form) to another program. The program then processes that data and the server then "captures" the resulting output from that program — typically a web page — and passes the program's response back to the Web browser. With CGI, you can write scripts that create interactive, user-driven applications. CGI Overview
Rather than limiting the Web to documents written ahead of time, CGI enables Web pages to be created on the fly, based upon the input of users. You can use CGI scripts to create a wide range of applications, from surveys to search tools, from Internet service gateways to quizzes and games. You can count the number of users who access a document or let them sign an electronic guest book. You can provide users with all types of information, collect their comments, and respond to them. CGI's strength is its flexibility. CGI can be used to develop applications on nearly every Webserver in existence. Another important advantage of CGI is that it doesn't really care what script or programming language you use for your applications. It simply passes the message between the Webserver and the host computer. CGI "scripts" are commonly written in Perl, but they can also be written in C, C++, COBOL, TCL/Tk, Python, Visual Basic, AppleScript, UNIX Shell scripts (Bourne, csh, etc.), or any other language that the host computer can understand. Since most of these programming and scripting languages are available on all the popular operating systems, running CGI scripts is an option for just about anyone. There are significant downsides to CGI scripts as well. The main one is that CGI scripts act like any other program or script running on a computer — they need to be owned and executed by someone. Given the fundamental openness of the Web, this creates a number of problems. The first is that, in most cases, there's a single user account associated with the Webserver—often called something like WEBUSER. Every time a web page accesses an application through CGI, a new instance of that user is created to run the requested program. This means that if you have a large, complicated shopping cart program on your site and 100 users are visiting, 100 copies of that program are being simultaneously executed by WEBUSER. This creates a definite performance problem. NOTE: Just about all the new Webservers today have solved the problem of having to create a new instance of a CGI process for each requested program. The CGI requests all run in one process with each request running as a separate thread. A further problem for CGI applications is security. Since every CGI application is executed by the same user account (e.g. WEBUSER), every application accessible through CGI needs to have permissions set that allow WEBUSER to execute it, but not necessarily to read or modify it. There are ways to handle these security issues; the point is that it is easy to leave files compromised, especially if you are a novice to CGI and/or permission management. Regardless of the performance and security issues, CGI is by far the most common way for Webservers to access other applications. Its success may be attributable to the fact that it's straightforward, cross-platform, and compatible with traditional languages such as C and Perl. There are a number of ways to access databases through CGI, particularly using Perl libraries or custom C code. Many more sophisticated web database application servers can provide some portion of their capabilities as a CGI application. Most of these sophisticated platforms, however, use API access instead.
Gateway program, CGI program, and CGI script are essentially three names for the same thing. CGI programs contain the code that accepts data from the Webserver (most often passed on from its Web clients) and does something with that data. Tasks can range from various forms of processing, accessing information resources, creating output, or all of these. CGI programs can be developed in virtually any language supported on the Webserver host machine, including compiled and interpreted languages such as C, C++, Java, JavaScript, Visual Basic, FORTRAN, Perl, Awk, Expect, and Tcl, as well as some of the newer Perl extensions for client/server database access — for example, Sybperl and Oraperl.
CGI programs are always placed on a disk that the Webserver has access to. This means that if you are using a dial-up account to maintain your Web site, you need to upload your CGI programs to the server before they can be run. Webservers are generally configured so that all CGI applications are placed into a cgi-bin directory. However, the Webserver may have aliases so that "virtual directories" exist. Each user might have his or her own cgi-bin directory. The directory location is totally under the control of your Web site administrator.
|