3 # See the bottom of this file for the POD documentation. Search for the
6 # You can run this file through either pod2man or pod2html to produce pretty
7 # documentation in manual or html file format (these utilities are part of the
8 # Perl 5 distribution).
10 # Copyright 1995,1996, Lincoln D. Stein. All rights reserved.
11 # It may be used and modified freely, but I do request that this copyright
12 # notice remain attached to the file. You may modify this module as you
13 # wish, but if you redistribute a modified version, please attach a note
14 # listing the modifications you have made.
16 $CGI::Fast::VERSION='1.07';
22 # workaround for known bug in libfcgi
23 while (($ignore) = each %ENV) { }
25 # override the initialization behavior so that
26 # state is NOT maintained between invocations
31 # If ENV{FCGI_SOCKET_PATH} is specified, we maintain a FCGI Request handle
32 # in this package variable.
33 use vars qw($Ext_Request);
35 # If ENV{FCGI_SOCKET_PATH} is given, explicitly open the socket,
36 # and keep the request handle around from which to call Accept().
37 if ($ENV{FCGI_SOCKET_PATH}) {
38 my $path = $ENV{FCGI_SOCKET_PATH};
39 my $backlog = $ENV{FCGI_LISTEN_QUEUE} || 100;
40 my $socket = FCGI::OpenSocket( $path, $backlog );
41 $Ext_Request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR,
46 # New is slightly different in that it calls FCGI's
49 my ($self, $initializer, @param) = @_;
50 unless (defined $initializer) {
52 return undef unless $Ext_Request->Accept() >= 0;
54 return undef unless FCGI::accept() >= 0;
58 $self->_setup_symbols(@SAVED_SYMBOLS) if @CGI::SAVED_SYMBOLS;
59 return $CGI::Q = $self->SUPER::new($initializer, @param);
66 CGI::Fast - CGI Interface for Fast CGI
70 use CGI::Fast qw(:standard);
72 while (new CGI::Fast) {
74 print start_html("Fast CGI Rocks");
77 "Invocation number ",b($COUNTER++),
85 CGI::Fast is a subclass of the CGI object created by
86 CGI.pm. It is specialized to work well with the Open Market
87 FastCGI standard, which greatly speeds up CGI scripts by
88 turning them into persistently running server processes. Scripts
89 that perform time-consuming initialization processes, such as
90 loading large modules or opening persistent database connections,
91 will see large performance improvements.
93 =head1 OTHER PIECES OF THE PUZZLE
95 In order to use CGI::Fast you'll need a FastCGI-enabled Web
96 server. See http://www.fastcgi.com/ for details.
98 =head1 WRITING FASTCGI PERL SCRIPTS
100 FastCGI scripts are persistent: one or more copies of the script
101 are started up when the server initializes, and stay around until
102 the server exits or they die a natural death. After performing
103 whatever one-time initialization it needs, the script enters a
104 loop waiting for incoming connections, processing the request, and
107 A typical FastCGI script will look like this:
109 #!/usr/local/bin/perl # must be a FastCGI version of perl!
111 &do_some_initialization();
112 while ($q = new CGI::Fast) {
113 &process_request($q);
116 Each time there's a new request, CGI::Fast returns a
117 CGI object to your loop. The rest of the time your script
118 waits in the call to new(). When the server requests that
119 your script be terminated, new() will return undef. You can
120 of course exit earlier if you choose. A new version of the
121 script will be respawned to take its place (this may be
122 necessary in order to avoid Perl memory leaks in long-running
125 CGI.pm's default CGI object mode also works. Just modify the loop
128 while (new CGI::Fast) {
132 Calls to header(), start_form(), etc. will all operate on the
135 =head1 INSTALLING FASTCGI SCRIPTS
137 See the FastCGI developer's kit documentation for full details. On
138 the Apache server, the following line must be added to srm.conf:
140 AddType application/x-httpd-fcgi .fcgi
142 FastCGI scripts must end in the extension .fcgi. For each script you
143 install, you must add something like the following to srm.conf:
145 FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
147 This instructs Apache to launch two copies of file_upload.fcgi at
150 =head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
152 Any script that works correctly as a FastCGI script will also work
153 correctly when installed as a vanilla CGI script. However it will
154 not see any performance benefit.
156 =head1 EXTERNAL FASTCGI SERVER INVOCATION
158 FastCGI supports a TCP/IP transport mechanism which allows FastCGI scripts to run
159 external to the webserver, perhaps on a remote machine. To configure the
160 webserver to connect to an external FastCGI server, you would add the following
163 FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888
165 Two environment variables affect how the C<CGI::Fast> object is created,
166 allowing C<CGI::Fast> to be used as an external FastCGI server. (See C<FCGI>
167 documentation for C<FCGI::OpenSocket> for more information.)
171 =item FCGI_SOCKET_PATH
173 The address (TCP/IP) or path (UNIX Domain) of the socket the external FastCGI
174 script to which bind an listen for incoming connections from the web server.
176 =item FCGI_LISTEN_QUEUE
178 Maximum length of the queue of pending connections.
184 #!/usr/local/bin/perl # must be a FastCGI version of perl!
186 &do_some_initialization();
187 $ENV{FCGI_SOCKET_PATH} = "sputnik:8888";
188 $ENV{FCGI_LISTEN_QUEUE} = 100;
189 while ($q = new CGI::Fast) {
190 &process_request($q);
195 I haven't tested this very much.
197 =head1 AUTHOR INFORMATION
199 Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
201 This library is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself.
204 Address bug reports and comments to: lstein@cshl.org
208 This section intentionally left blank.