Track /etc/gitconfig
[msysgit/mtrensch.git] / lib / perl5 / 5.8.8 / CGI / Fast.pm
blob43b8709a16537636d1d23cd007e761bd4130bbf4
1 package CGI::Fast;
3 # See the bottom of this file for the POD documentation. Search for the
4 # string '=head'.
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 # The most recent version and complete docs are available at:
17 # http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
18 # ftp://ftp-genome.wi.mit.edu/pub/software/WWW/
19 $CGI::Fast::VERSION='1.05';
21 use CGI;
22 use FCGI;
23 @ISA = ('CGI');
25 # workaround for known bug in libfcgi
26 while (($ignore) = each %ENV) { }
28 # override the initialization behavior so that
29 # state is NOT maintained between invocations
30 sub save_request {
31 # no-op
34 # If ENV{FCGI_SOCKET_PATH} is specified, we maintain a FCGI Request handle
35 # in this package variable.
36 use vars qw($Ext_Request);
37 BEGIN {
38 # If ENV{FCGI_SOCKET_PATH} is given, explicitly open the socket,
39 # and keep the request handle around from which to call Accept().
40 if ($ENV{FCGI_SOCKET_PATH}) {
41 my $path = $ENV{FCGI_SOCKET_PATH};
42 my $backlog = $ENV{FCGI_LISTEN_QUEUE} || 100;
43 my $socket = FCGI::OpenSocket( $path, $backlog );
44 $Ext_Request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR,
45 \%ENV, $socket, 1 );
49 # New is slightly different in that it calls FCGI's
50 # accept() method.
51 sub new {
52 my ($self, $initializer, @param) = @_;
53 unless (defined $initializer) {
54 if ($Ext_Request) {
55 return undef unless $Ext_Request->Accept() >= 0;
56 } else {
57 return undef unless FCGI::accept() >= 0;
60 return $CGI::Q = $self->SUPER::new($initializer, @param);
65 =head1 NAME
67 CGI::Fast - CGI Interface for Fast CGI
69 =head1 SYNOPSIS
71 use CGI::Fast qw(:standard);
72 $COUNTER = 0;
73 while (new CGI::Fast) {
74 print header;
75 print start_html("Fast CGI Rocks");
76 print
77 h1("Fast CGI Rocks"),
78 "Invocation number ",b($COUNTER++),
79 " PID ",b($$),".",
80 hr;
81 print end_html;
84 =head1 DESCRIPTION
86 CGI::Fast is a subclass of the CGI object created by
87 CGI.pm. It is specialized to work well with the Open Market
88 FastCGI standard, which greatly speeds up CGI scripts by
89 turning them into persistently running server processes. Scripts
90 that perform time-consuming initialization processes, such as
91 loading large modules or opening persistent database connections,
92 will see large performance improvements.
94 =head1 OTHER PIECES OF THE PUZZLE
96 In order to use CGI::Fast you'll need a FastCGI-enabled Web
97 server. Open Market's server is FastCGI-savvy. There are also
98 freely redistributable FastCGI modules for NCSA httpd 1.5 and Apache.
99 FastCGI-enabling modules for Microsoft Internet Information Server and
100 Netscape Communications Server have been announced.
102 In addition, you'll need a version of the Perl interpreter that has
103 been linked with the FastCGI I/O library. Precompiled binaries are
104 available for several platforms, including DEC Alpha, HP-UX and
105 SPARC/Solaris, or you can rebuild Perl from source with patches
106 provided in the FastCGI developer's kit. The FastCGI Perl interpreter
107 can be used in place of your normal Perl without ill consequences.
109 You can find FastCGI modules for Apache and NCSA httpd, precompiled
110 Perl interpreters, and the FastCGI developer's kit all at URL:
112 http://www.fastcgi.com/
114 =head1 WRITING FASTCGI PERL SCRIPTS
116 FastCGI scripts are persistent: one or more copies of the script
117 are started up when the server initializes, and stay around until
118 the server exits or they die a natural death. After performing
119 whatever one-time initialization it needs, the script enters a
120 loop waiting for incoming connections, processing the request, and
121 waiting some more.
123 A typical FastCGI script will look like this:
125 #!/usr/local/bin/perl # must be a FastCGI version of perl!
126 use CGI::Fast;
127 &do_some_initialization();
128 while ($q = new CGI::Fast) {
129 &process_request($q);
132 Each time there's a new request, CGI::Fast returns a
133 CGI object to your loop. The rest of the time your script
134 waits in the call to new(). When the server requests that
135 your script be terminated, new() will return undef. You can
136 of course exit earlier if you choose. A new version of the
137 script will be respawned to take its place (this may be
138 necessary in order to avoid Perl memory leaks in long-running
139 scripts).
141 CGI.pm's default CGI object mode also works. Just modify the loop
142 this way:
144 while (new CGI::Fast) {
145 &process_request;
148 Calls to header(), start_form(), etc. will all operate on the
149 current request.
151 =head1 INSTALLING FASTCGI SCRIPTS
153 See the FastCGI developer's kit documentation for full details. On
154 the Apache server, the following line must be added to srm.conf:
156 AddType application/x-httpd-fcgi .fcgi
158 FastCGI scripts must end in the extension .fcgi. For each script you
159 install, you must add something like the following to srm.conf:
161 FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
163 This instructs Apache to launch two copies of file_upload.fcgi at
164 startup time.
166 =head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
168 Any script that works correctly as a FastCGI script will also work
169 correctly when installed as a vanilla CGI script. However it will
170 not see any performance benefit.
172 =head1 EXTERNAL FASTCGI SERVER INVOCATION
174 FastCGI supports a TCP/IP transport mechanism which allows FastCGI scripts to run
175 external to the webserver, perhaps on a remote machine. To configure the
176 webserver to connect to an external FastCGI server, you would add the following
177 to your srm.conf:
179 FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888
181 Two environment variables affect how the C<CGI::Fast> object is created,
182 allowing C<CGI::Fast> to be used as an external FastCGI server. (See C<FCGI>
183 documentation for C<FCGI::OpenSocket> for more information.)
185 =over
187 =item FCGI_SOCKET_PATH
189 The address (TCP/IP) or path (UNIX Domain) of the socket the external FastCGI
190 script to which bind an listen for incoming connections from the web server.
192 =item FCGI_LISTEN_QUEUE
194 Maximum length of the queue of pending connections.
196 =back
198 For example:
200 #!/usr/local/bin/perl # must be a FastCGI version of perl!
201 use CGI::Fast;
202 &do_some_initialization();
203 $ENV{FCGI_SOCKET_PATH} = "sputnik:8888";
204 $ENV{FCGI_LISTEN_QUEUE} = 100;
205 while ($q = new CGI::Fast) {
206 &process_request($q);
209 =head1 CAVEATS
211 I haven't tested this very much.
213 =head1 AUTHOR INFORMATION
215 Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
217 This library is free software; you can redistribute it and/or modify
218 it under the same terms as Perl itself.
220 Address bug reports and comments to: lstein@cshl.org
222 =head1 BUGS
224 This section intentionally left blank.
226 =head1 SEE ALSO
228 L<CGI::Carp>, L<CGI>
230 =cut