Table of Contents
Fcgi.tcl - Tcl support for the FastCGI protocol
Fcgi.tcl
allows Tcl programs to be used in FastCGI applications. Fcgi.tcl requires
Tcl version 8.0 and higher, and Extended Tcl (TclX) version 8.x and higher.
package require Fcgi
FCGI_Accept
FCGI_Finish
FCGI_SetExitStatus
n
FCGI_StartFilterData
FCGI_SetBufSize n
FastCGI programs
are started by an 'AppClass' directive from a web server that supports
FastCGI, or are started manually and accessed from a web server via the
'ExternalAppClass' directive.
Fcgi.tcl comes in two flavors: a 100% Tcl version,
and another which is a C extension. Each fcgi.tcl flavor provides the same
programming interface.
When a program using the 100% Tcl flavor of Fcgi.tcl
is started by 'AppClass', Fcgi.tcl assumes that file descriptor 0 is a socket
that is used to accept new connections. When using 'AppClass' style connections,
Fcgi.tcl requires Extended Tcl (TclX).
If 'ExternalAppClass' is used, the
FastCGI Tcl program must be started manually. In this case, Fcgi.tcl expects
the command line argument -port x or the environment variable PORT to specify
the port on which to listen for connection. 'ExternalAppClass' style connections
do not require Extended Tcl (TclX).
Programs using the C extension flavor
of Fcgi.tcl don't require TclX. Programs started as 'ExternalAppClass', must
be started with 'driver.tcl' or similar program. Driver.tcl requires Extended
Tcl (TclX).
- FCGI_Accept
-
Accept a new FastCGI connection. FCGI_Accept
returns "0" for a new connection, or "-1" if an error was encountered.
If the application was invoked as a CGI program, FCGI_Accept will return
"0" for the first call to it, then return "-1" on subsequent calls. This
allows a properly coded FastCGI program to work in a convential CGI environment.
FCGI_Accept sets environment variables to that of the initial enviroment
plus variables for the FastCGI connection. FCGI_Accept will call FCGI_Finish
if a previous response is still pending before accepting a new request.
Additionally, FCGI_Accept sets the environment variable FCGI_ROLE
to one of three values, depending of the type of the FastCGI connection:
- RESPONDER
-
The FastCGI program receives CGI/1.1 environment variables.
The FastCGI program will receive at most CONTENT_LENGTH bytes of data
on the Tcl channel stdin . The FastCGI program should respond the the
request as a typical CGI program by writing its output on the Tcl channel
stdout .
- AUTHORIZER
-
The FastCGI program receives HTTP request information
as environment variables. The FastCGI program will receive at most CONTENT_LENGTH
bytes of data on the Tcl channel stdin . The FastCGI program should respond
as status 200 to indicate access should be granted. The FastCGI program
may also send HTTP headers that are prefixed with Variable- by writing
on stdout .
- FILTER
-
The FastCGI program receives CGI/1.1 environment variables.
The FastCGI program will receive at most CONTENT_LENGTH bytes of data
on the Tcl channel stdin . After all of stdin has been read, the FastCGI
program may call FCGI_StartFilterData to receive the additional data stream.
The FastCGI program will then receive at most FCGI_DATA_LENGTH bytes
on the Tcl channel stdin .
- FCGI_Finish
-
Finish a FastCGI connection
by flushing output buffers and sending an exit status code. If an exit
code has not been set by calling FCGI_SetExitStatus, FCGI_Finish assumes
a code of "0".
- FCGI_SetExitStatus status-code
-
Set an exit code for the
most current FastCGI connection. The last call to FCGI_SetExitStatus sets
the status code to be returned upon calling FCGI_Finish. status-code should
be a numeric integer.
- FCGI_StartFilterData
-
Start receiving the FCGI_DATA
data stream as the Tcl channel stdin . Any previous data left unread on
the stdin stream will be lost. FCGI_DATA is only received when the FastCGI
application's role is FILTER.
- FCGI_SetBufSize buffer-size
-
Sets the size
of the output buffer for Tcl channels stdout and stderr . The default
buffer size for each channel is 4096 bytes. A buffer size of "0" causes
output to be flushed on every puts to stdout or stderr. The maximum buffer
size allowed is 65536 bytes.
FastCGI output may also be flushed at any
time by calling the Tcl command flush stdout .
Currently,
the Fcgi.tcl package is single threaded, and replies to FastCGI managment
records as:
- FCGI_MAX_CONNS
- "1"
- FCGI_MAX_REQS
- "1"
- FCGI_MPXS_CONNS
- "0"
cgi.tcl, a Tcl package for writing CGI programs, by Don Libes.
http://expect.nist.gov/cgi.tcl.
FastCGI documentation.
http://www.fastcgi.com
Unoffical FastCGI page.
http://fastcgi.idle.com
See the files
README, INSTALL and NOTES for additional information and Apache Server
configuration. Fcgi.tcl is an orginal implementation of the FastCGI protocol,
version 1.0 dated Arpil 29, 1996 by Mark R. Brown, Open Market, Inc. Fcgi.tcl
is compatiable with the libfcgi library available with the FastCGI developer's
kit for Tcl.
If cgi.tcl is used in the same application as Fcgi.tcl, you
should order package require commands as:
package require cgi
package
require Fcgi
Cgi.tcl uses the global array _cgi to hold state information.
FCGI_Accept will set the _cgi array to beginning values so that its
state information will be reset for each new connection.
Tom Poindexter,
tpoindex@nyx.net, Talus Technologies, Inc., Highlands Ranch, CO. http://www.nyx.net/~tpoindex
Copyright 1998 Tom Poindexter. See the file 'LICENSE.TERMS' for additional
copyright and licensing terms.
Table of Contents