1CGI::Fast(3pm) Perl Programmers Reference Guide CGI::Fast(3pm)
2
3
4
6 CGI::Fast - CGI Interface for Fast CGI
7
9 use CGI::Fast qw(:standard);
10 $COUNTER = 0;
11 while (new CGI::Fast) {
12 print header;
13 print start_html("Fast CGI Rocks");
14 print
15 h1("Fast CGI Rocks"),
16 "Invocation number ",b($COUNTER++),
17 " PID ",b($$),".",
18 hr;
19 print end_html;
20 }
21
23 CGI::Fast is a subclass of the CGI object created by CGI.pm. It is
24 specialized to work well with the Open Market FastCGI standard, which
25 greatly speeds up CGI scripts by turning them into persistently running
26 server processes. Scripts that perform time-consuming initialization
27 processes, such as loading large modules or opening persistent database
28 connections, will see large performance improvements.
29
31 In order to use CGI::Fast you'll need a FastCGI-enabled Web server.
32 Open Market's server is FastCGI-savvy. There are also freely redis‐
33 tributable FastCGI modules for NCSA httpd 1.5 and Apache. FastCGI-
34 enabling modules for Microsoft Internet Information Server and Netscape
35 Communications Server have been announced.
36
37 In addition, you'll need a version of the Perl interpreter that has
38 been linked with the FastCGI I/O library. Precompiled binaries are
39 available for several platforms, including DEC Alpha, HP-UX and
40 SPARC/Solaris, or you can rebuild Perl from source with patches pro‐
41 vided in the FastCGI developer's kit. The FastCGI Perl interpreter can
42 be used in place of your normal Perl without ill consequences.
43
44 You can find FastCGI modules for Apache and NCSA httpd, precompiled
45 Perl interpreters, and the FastCGI developer's kit all at URL:
46
47 http://www.fastcgi.com/
48
50 FastCGI scripts are persistent: one or more copies of the script are
51 started up when the server initializes, and stay around until the
52 server exits or they die a natural death. After performing whatever
53 one-time initialization it needs, the script enters a loop waiting for
54 incoming connections, processing the request, and waiting some more.
55
56 A typical FastCGI script will look like this:
57
58 #!/usr/local/bin/perl # must be a FastCGI version of perl!
59 use CGI::Fast;
60 &do_some_initialization();
61 while ($q = new CGI::Fast) {
62 &process_request($q);
63 }
64
65 Each time there's a new request, CGI::Fast returns a CGI object to your
66 loop. The rest of the time your script waits in the call to new().
67 When the server requests that your script be terminated, new() will
68 return undef. You can of course exit earlier if you choose. A new
69 version of the script will be respawned to take its place (this may be
70 necessary in order to avoid Perl memory leaks in long-running scripts).
71
72 CGI.pm's default CGI object mode also works. Just modify the loop this
73 way:
74
75 while (new CGI::Fast) {
76 &process_request;
77 }
78
79 Calls to header(), start_form(), etc. will all operate on the current
80 request.
81
83 See the FastCGI developer's kit documentation for full details. On the
84 Apache server, the following line must be added to srm.conf:
85
86 AddType application/x-httpd-fcgi .fcgi
87
88 FastCGI scripts must end in the extension .fcgi. For each script you
89 install, you must add something like the following to srm.conf:
90
91 FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
92
93 This instructs Apache to launch two copies of file_upload.fcgi at
94 startup time.
95
97 Any script that works correctly as a FastCGI script will also work cor‐
98 rectly when installed as a vanilla CGI script. However it will not see
99 any performance benefit.
100
102 FastCGI supports a TCP/IP transport mechanism which allows FastCGI
103 scripts to run external to the webserver, perhaps on a remote machine.
104 To configure the webserver to connect to an external FastCGI server,
105 you would add the following to your srm.conf:
106
107 FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888
108
109 Two environment variables affect how the "CGI::Fast" object is created,
110 allowing "CGI::Fast" to be used as an external FastCGI server. (See
111 "FCGI" documentation for "FCGI::OpenSocket" for more information.)
112
113 FCGI_SOCKET_PATH
114 The address (TCP/IP) or path (UNIX Domain) of the socket the exter‐
115 nal FastCGI script to which bind an listen for incoming connections
116 from the web server.
117
118 FCGI_LISTEN_QUEUE
119 Maximum length of the queue of pending connections.
120
121 For example:
122
123 #!/usr/local/bin/perl # must be a FastCGI version of perl!
124 use CGI::Fast;
125 &do_some_initialization();
126 $ENV{FCGI_SOCKET_PATH} = "sputnik:8888";
127 $ENV{FCGI_LISTEN_QUEUE} = 100;
128 while ($q = new CGI::Fast) {
129 &process_request($q);
130 }
131
133 I haven't tested this very much.
134
136 Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
137
138 This library is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140
141 Address bug reports and comments to: lstein@cshl.org
142
144 This section intentionally left blank.
145
147 CGI::Carp, CGI
148
149
150
151perl v5.8.8 2001-09-21 CGI::Fast(3pm)