The Common Gateway Interface (CGI) specification was introduced to enable and standardize the interface between Web servers and external programs. The CGI is a relatively simple, platform and language independent, industry-standard interface for Web application development. Programs that implement the CGI standard are commonly called CGI programs.

The purpose of CGI is to extend the capability of an HTTP server by providing framework in which an HTTP server can interface with a program that is specified on a URL. The format of the URL allows parameters to be passed to the CGI program. On the server side, the interface describes how the program is started by the HTTP server and how parameters for the program are passed using a combination of standard-input and environment variables. It also describes how output information (such as HTML elements) are passed back to the HTTP server using standard output. Thus, in its simplest form, a CGI program can be defined as a program that:

  1. Can be called as an executable program and run as a child process of the HTTP server.
  2. Is able to read from the standard input.
  3. Is able to access environment variables.
  4. Is able to write to the standard output.
  5. Is able to access command- line arguments passed to the program.

The administrator controls which CGI programs the system can run by using the server directives. The server recognizes a URL that contains a request for a CGI program, commonly called a CGI script. (Throughout the documentation, we use the terms CGI program and CGI script to mean the same thing.) Depending on the server directives, the server calls that program on behalf of the client.

The server supports CGI programs that are written in C++, REXX, ILE C, ILE RPG, and ILE COBOL. It also supports multiple thread capable CGI programs in all languages that support multiple threads.

CGI programs that are created by compiling source code typically run faster than programs that are written in interpreted languages such as the Net.Data® and PHP scripting languages. However, programs that are written in scripting languages tend to be easier to write, maintain, and debug.

The support for CGI by IBM® HTTP Server for i includes support for IBM i-unique features that improve the CGI programming model in the areas of performance, high-availability, and support for transactions. The following sections discuss the various features.

HTTP Server CGI processes

A major concern with CGI performance on other platforms is the fact that a CGI program is started on each Web client request. This includes additional disk and operating system activity to create the new process (job). Quite often, CGI program initialization, such as connecting to a database management system, also takes some time that adds to the response time users experience with such applications.

The IBM HTTP Server for i takes a different approach. The HTTP Server keeps a pool of HTTP server child processes that is used to run CGI programs. The child processes are not ended after a CGI program is run within the process. In addition, child processes are associated with a user profile and only requests for CGI programs that run under the same user profile associated with an existing child process will be run in the process.

Some of the additional features related to CGI processes include:

  • The ability to specify how many child processes, and under what user profile, should be pre-started when the Web server starts so that Web clients do not incur the performance hit of starting a new CGI child process.
  • The ability to run a CGI request in a pre-started CGI process, enabling the CGI program to be loaded and initialized at server startup. This support is beneficial for programs running in named activation groups. A CGI program running in a named activation group is loaded and initialized one time within a CGI process.

Persistent CGI programs

Persistent CGI is an extension to the CGI interface that allows a CGI program to maintain a session with a browser client across multiple browser requests. This allows files to be left open, the state to be maintained, and long running database transactions to be committed or rolled-back based on end-user actions.

High availability CGI programs

High availability CGI programs use APIs to preserve state information. The state information can be accessed by different IBM i servers that are participating as cluster nodes in a clustered environment, even after a failure or switchover of the HTTP Server or IBM i server.

Note: Although maintaining CGI program state information across multiple requests is a concept used by both persistent CGI and high availability CGI programs, the mechanisms used by the two types of programs are different and a high availability CGI program should not be confused with a persistent CGI program.

Running AIX CGI programs

The IBM HTTP Server for i is able to run AIX® CGI programs by running the CGI program in the IBM Portable Application Solutions Environment for i.

In addition to running AIX CGI programs, the IBM HTTP Server for i is able to run AIX programs that implement the FastCGI protocol. FastCGI is an interface between Web servers and applications which combines some of the performance characteristics of native Web server modules with the Web server independence of the CGI programming interface. Like AIX CGI programs, AIX FastCGI applications are run in the PASE for i environment.