Sun Java System Web Server 7.0 Update 4 Administrator's Guide

Developing FastCGI Applications

FastCGI applications can be developed using Perl, PHP, C and Java. The following sections briefly describe the procedure to develop the application using some of the popular programming languages.

ProcedureExecuting a FastCGI Application

  1. Stop the Web Server.

  2. Restart the Web Server.

  3. Access the application that has "fcgi" as the application root.

    For Example: http://localhost/fcgi/ListDir.php

Structure of a FastCGI Application

A typical FastCGI application has the following code structure:

Initialization code

Start of response loop
		body of response loop
End of response loop

The initialization code is run only once at the time of the application initialization. Initialization code usually performs time-consuming operations such as opening databases or calculating values for tables or bitmaps. The main task of converting a CGI program into a FastCGI program is to separate the initialization code from the code that needs to run for each request.

The response loop runs continuously, waiting for client requests to arrive. The loop starts with a call to FCGI_Accept, a routine in the FastCGI library. The FCGI_Accept routine blocks program execution until a client requests the FastCGI application. When a client request comes in, FCGI_Accept unblocks, runs one iteration of the response loop body, and then blocks again waiting for another client request. The loop terminates only when a System Administrator or the Web Server kills the FastCGI application.

Using Perl

Download and install the latest FCGI module from CPAN. For ActivePerl, the modules can be downloaded from http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/Zips.

For more information on writing FastCGI applications using Perl, see http://www.fastcgi.com/#TheDevKit

Using PHP

Beginning with PHP 4.3.0, FastCGI became a supported configuration for the PHP engine. To compile the PHP 4.3.x or greater engine with support for FastCGI, include the configure switch --enable-fastcgi as part of the build process, for example:


./configure <other-options> --enable-fastcgi
gmake

After compilation, the php binary will be FastCGI enabled.

When using PHP versions 5.1.2 or earlier (including PHP 4.x) the FastCGI plug-in should be configured with bind-path in host:port format. For example, bind-path = “localhost:3333”.

For PHP versions 5.1.3 and later, the bind-path is optional. If specified, it should not be in “host:port” format. It can be a string. For example, bind-path = “myphpbindpath”.

Using C/Java

FastCGI development kit provides APIs to write FastCGI C/Java applications. You can download the kit from http://www.fastcgi.com/devkit/doc/fcgi-devel-kit.htm.

To build the downloaded FastCGI development kit, perform the following steps:

  1. Unpack the tar file. This action creates a new directory called fcgi-devel-kit

  2. Execute this sequence of commands in the fcgi-devel-kit directory:

    1. ./configure

    2. make

For more information on writing FastCGI applications using C, see http://www.fastcgi.com/devkit/doc/fcgi-devel-kit.htm#S3

For more information on writing FastCGI applications using Java, see http://www.fastcgi.com/devkit/doc/fcgi-java.htm