This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fixing extra -I's with PERL_CORE
[perl5.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/
3538e1d5 19$CGI::Fast::VERSION='1.02';
54310121 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 {
71f3e297
JH
37 my ($self, $initializer, @param) = @_;
38 unless (defined $initializer) {
39 return undef unless FCGI::accept() >= 0;
40 }
41 return $CGI::Q = $self->SUPER::new($initializer, @param);
54310121 42}
43
441;
45
46=head1 NAME
47
48CGI::Fast - CGI Interface for Fast CGI
49
50=head1 SYNOPSIS
51
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;
63 }
64
65=head1 DESCRIPTION
66
67CGI::Fast is a subclass of the CGI object created by
68CGI.pm. It is specialized to work well with the Open Market
69FastCGI standard, which greatly speeds up CGI scripts by
70turning them into persistently running server processes. Scripts
71that perform time-consuming initialization processes, such as
72loading large modules or opening persistent database connections,
73will see large performance improvements.
74
75=head1 OTHER PIECES OF THE PUZZLE
76
77In order to use CGI::Fast you'll need a FastCGI-enabled Web
78server. Open Market's server is FastCGI-savvy. There are also
79freely redistributable FastCGI modules for NCSA httpd 1.5 and Apache.
80FastCGI-enabling modules for Microsoft Internet Information Server and
81Netscape Communications Server have been announced.
82
83In addition, you'll need a version of the Perl interpreter that has
84been linked with the FastCGI I/O library. Precompiled binaries are
85available for several platforms, including DEC Alpha, HP-UX and
86SPARC/Solaris, or you can rebuild Perl from source with patches
87provided in the FastCGI developer's kit. The FastCGI Perl interpreter
88can be used in place of your normal Perl without ill consequences.
89
90You can find FastCGI modules for Apache and NCSA httpd, precompiled
91Perl interpreters, and the FastCGI developer's kit all at URL:
92
93 http://www.fastcgi.com/
94
95=head1 WRITING FASTCGI PERL SCRIPTS
96
97FastCGI scripts are persistent: one or more copies of the script
98are started up when the server initializes, and stay around until
99the server exits or they die a natural death. After performing
100whatever one-time initialization it needs, the script enters a
101loop waiting for incoming connections, processing the request, and
102waiting some more.
103
104A typical FastCGI script will look like this:
105
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);
111 }
112
113Each time there's a new request, CGI::Fast returns a
114CGI object to your loop. The rest of the time your script
115waits in the call to new(). When the server requests that
116your script be terminated, new() will return undef. You can
117of course exit earlier if you choose. A new version of the
118script will be respawned to take its place (this may be
119necessary in order to avoid Perl memory leaks in long-running
120scripts).
121
122CGI.pm's default CGI object mode also works. Just modify the loop
123this way:
124
125 while (new CGI::Fast) {
126 &process_request;
127 }
128
129Calls to header(), start_form(), etc. will all operate on the
130current request.
131
132=head1 INSTALLING FASTCGI SCRIPTS
133
134See the FastCGI developer's kit documentation for full details. On
135the Apache server, the following line must be added to srm.conf:
136
137 AddType application/x-httpd-fcgi .fcgi
138
139FastCGI scripts must end in the extension .fcgi. For each script you
140install, you must add something like the following to srm.conf:
141
142 AppClass /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
143
144This instructs Apache to launch two copies of file_upload.fcgi at
145startup time.
146
147=head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
148
149Any script that works correctly as a FastCGI script will also work
150correctly when installed as a vanilla CGI script. However it will
151not see any performance benefit.
152
153=head1 CAVEATS
154
155I haven't tested this very much.
156
157=head1 AUTHOR INFORMATION
158
71f3e297 159Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
54310121 160
71f3e297
JH
161This library is free software; you can redistribute it and/or modify
162it under the same terms as Perl itself.
163
164Address bug reports and comments to: lstein@cshl.org
54310121 165
166=head1 BUGS
167
168This section intentionally left blank.
169
170=head1 SEE ALSO
171
172L<CGI::Carp>, L<CGI>
3cb6de81 173
54310121 174=cut