Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / CGI / Fast.pm
blobb4851862dca48a95f38ce9e3e891327c52937be8
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.02';
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 # New is slightly different in that it calls FCGI's
35 # accept() method.
36 sub new {
37 my ($self, $initializer, @param) = @_;
38 unless (defined $initializer) {
39 return undef unless FCGI::accept() >= 0;
41 return $CGI::Q = $self->SUPER::new($initializer, @param);
46 =head1 NAME
48 CGI::Fast - CGI Interface for Fast CGI
50 =head1 SYNOPSIS
52 use CGI::Fast qw(:standard);
53 $COUNTER = 0;
54 while (new CGI::Fast) {
55 print header;
56 print start_html("Fast CGI Rocks");
57 print
58 h1("Fast CGI Rocks"),
59 "Invocation number ",b($COUNTER++),
60 " PID ",b($$),".",
61 hr;
62 print end_html;
65 =head1 DESCRIPTION
67 CGI::Fast is a subclass of the CGI object created by
68 CGI.pm. It is specialized to work well with the Open Market
69 FastCGI standard, which greatly speeds up CGI scripts by
70 turning them into persistently running server processes. Scripts
71 that perform time-consuming initialization processes, such as
72 loading large modules or opening persistent database connections,
73 will see large performance improvements.
75 =head1 OTHER PIECES OF THE PUZZLE
77 In order to use CGI::Fast you'll need a FastCGI-enabled Web
78 server. Open Market's server is FastCGI-savvy. There are also
79 freely redistributable FastCGI modules for NCSA httpd 1.5 and Apache.
80 FastCGI-enabling modules for Microsoft Internet Information Server and
81 Netscape Communications Server have been announced.
83 In addition, you'll need a version of the Perl interpreter that has
84 been linked with the FastCGI I/O library. Precompiled binaries are
85 available for several platforms, including DEC Alpha, HP-UX and
86 SPARC/Solaris, or you can rebuild Perl from source with patches
87 provided in the FastCGI developer's kit. The FastCGI Perl interpreter
88 can be used in place of your normal Perl without ill consequences.
90 You can find FastCGI modules for Apache and NCSA httpd, precompiled
91 Perl interpreters, and the FastCGI developer's kit all at URL:
93 http://www.fastcgi.com/
95 =head1 WRITING FASTCGI PERL SCRIPTS
97 FastCGI scripts are persistent: one or more copies of the script
98 are started up when the server initializes, and stay around until
99 the server exits or they die a natural death. After performing
100 whatever one-time initialization it needs, the script enters a
101 loop waiting for incoming connections, processing the request, and
102 waiting some more.
104 A typical FastCGI script will look like this:
106 #!/usr/local/bin/perl # must be a FastCGI version of perl!
107 use CGI::Fast;
108 &do_some_initialization();
109 while ($q = new CGI::Fast) {
110 &process_request($q);
113 Each time there's a new request, CGI::Fast returns a
114 CGI object to your loop. The rest of the time your script
115 waits in the call to new(). When the server requests that
116 your script be terminated, new() will return undef. You can
117 of course exit earlier if you choose. A new version of the
118 script will be respawned to take its place (this may be
119 necessary in order to avoid Perl memory leaks in long-running
120 scripts).
122 CGI.pm's default CGI object mode also works. Just modify the loop
123 this way:
125 while (new CGI::Fast) {
126 &process_request;
129 Calls to header(), start_form(), etc. will all operate on the
130 current request.
132 =head1 INSTALLING FASTCGI SCRIPTS
134 See the FastCGI developer's kit documentation for full details. On
135 the Apache server, the following line must be added to srm.conf:
137 AddType application/x-httpd-fcgi .fcgi
139 FastCGI scripts must end in the extension .fcgi. For each script you
140 install, you must add something like the following to srm.conf:
142 AppClass /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
144 This instructs Apache to launch two copies of file_upload.fcgi at
145 startup time.
147 =head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
149 Any script that works correctly as a FastCGI script will also work
150 correctly when installed as a vanilla CGI script. However it will
151 not see any performance benefit.
153 =head1 CAVEATS
155 I haven't tested this very much.
157 =head1 AUTHOR INFORMATION
159 Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
161 This library is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself.
164 Address bug reports and comments to: lstein@cshl.org
166 =head1 BUGS
168 This section intentionally left blank.
170 =head1 SEE ALSO
172 L<CGI::Carp>, L<CGI>
174 =cut