Sys::Syslog: hyphens in hostnames
[p5sagit/p5-mst-13.2.git] / lib / CGI / Fast.pm
CommitLineData
54310121 1package CGI::Fast;
2
3# See the bottom of this file for the POD documentation. Search for the
4# string '=head'.
5
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).
9
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.
15
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.00a';
20
21use CGI;
22use FCGI;
23@ISA = ('CGI');
24
25# workaround for known bug in libfcgi
26while (($ignore) = each %ENV) { }
27
28# override the initialization behavior so that
29# state is NOT maintained between invocations
30sub save_request {
31 # no-op
32}
33
34# New is slightly different in that it calls FCGI's
35# accept() method.
36sub new {
37 return undef unless FCGI::accept() >= 0;
38 my($self,@param) = @_;
39 return $CGI::Q = $self->SUPER::new(@param);
40}
41
421;
43
44=head1 NAME
45
46CGI::Fast - CGI Interface for Fast CGI
47
48=head1 SYNOPSIS
49
50 use CGI::Fast qw(:standard);
51 $COUNTER = 0;
52 while (new CGI::Fast) {
53 print header;
54 print start_html("Fast CGI Rocks");
55 print
56 h1("Fast CGI Rocks"),
57 "Invocation number ",b($COUNTER++),
58 " PID ",b($$),".",
59 hr;
60 print end_html;
61 }
62
63=head1 DESCRIPTION
64
65CGI::Fast is a subclass of the CGI object created by
66CGI.pm. It is specialized to work well with the Open Market
67FastCGI standard, which greatly speeds up CGI scripts by
68turning them into persistently running server processes. Scripts
69that perform time-consuming initialization processes, such as
70loading large modules or opening persistent database connections,
71will see large performance improvements.
72
73=head1 OTHER PIECES OF THE PUZZLE
74
75In order to use CGI::Fast you'll need a FastCGI-enabled Web
76server. Open Market's server is FastCGI-savvy. There are also
77freely redistributable FastCGI modules for NCSA httpd 1.5 and Apache.
78FastCGI-enabling modules for Microsoft Internet Information Server and
79Netscape Communications Server have been announced.
80
81In addition, you'll need a version of the Perl interpreter that has
82been linked with the FastCGI I/O library. Precompiled binaries are
83available for several platforms, including DEC Alpha, HP-UX and
84SPARC/Solaris, or you can rebuild Perl from source with patches
85provided in the FastCGI developer's kit. The FastCGI Perl interpreter
86can be used in place of your normal Perl without ill consequences.
87
88You can find FastCGI modules for Apache and NCSA httpd, precompiled
89Perl interpreters, and the FastCGI developer's kit all at URL:
90
91 http://www.fastcgi.com/
92
93=head1 WRITING FASTCGI PERL SCRIPTS
94
95FastCGI scripts are persistent: one or more copies of the script
96are started up when the server initializes, and stay around until
97the server exits or they die a natural death. After performing
98whatever one-time initialization it needs, the script enters a
99loop waiting for incoming connections, processing the request, and
100waiting some more.
101
102A typical FastCGI script will look like this:
103
104 #!/usr/local/bin/perl # must be a FastCGI version of perl!
105 use CGI::Fast;
106 &do_some_initialization();
107 while ($q = new CGI::Fast) {
108 &process_request($q);
109 }
110
111Each time there's a new request, CGI::Fast returns a
112CGI object to your loop. The rest of the time your script
113waits in the call to new(). When the server requests that
114your script be terminated, new() will return undef. You can
115of course exit earlier if you choose. A new version of the
116script will be respawned to take its place (this may be
117necessary in order to avoid Perl memory leaks in long-running
118scripts).
119
120CGI.pm's default CGI object mode also works. Just modify the loop
121this way:
122
123 while (new CGI::Fast) {
124 &process_request;
125 }
126
127Calls to header(), start_form(), etc. will all operate on the
128current request.
129
130=head1 INSTALLING FASTCGI SCRIPTS
131
132See the FastCGI developer's kit documentation for full details. On
133the Apache server, the following line must be added to srm.conf:
134
135 AddType application/x-httpd-fcgi .fcgi
136
137FastCGI scripts must end in the extension .fcgi. For each script you
138install, you must add something like the following to srm.conf:
139
140 AppClass /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
141
142This instructs Apache to launch two copies of file_upload.fcgi at
143startup time.
144
145=head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
146
147Any script that works correctly as a FastCGI script will also work
148correctly when installed as a vanilla CGI script. However it will
149not see any performance benefit.
150
151=head1 CAVEATS
152
153I haven't tested this very much.
154
155=head1 AUTHOR INFORMATION
156
157be used and modified freely, but I do request that this copyright
158notice remain attached to the file. You may modify this module as you
159wish, but if you redistribute a modified version, please attach a note
160listing the modifications you have made.
161
162Address bug reports and comments to:
163lstein@genome.wi.mit.edu
164
165=head1 BUGS
166
167This section intentionally left blank.
168
169=head1 SEE ALSO
170
171L<CGI::Carp>, L<CGI>
172
173=cut