1CGI::Fast(3) User Contributed Perl Documentation CGI::Fast(3)
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 FCGI module, which greatly speeds up CGI
25 scripts by turning them into persistently running server processes.
26 Scripts that perform time-consuming initialization processes, such as
27 loading large modules or opening persistent database connections, will
28 see large performance improvements.
29
31 In order to use CGI::Fast you'll need the FCGI module. See
32 http://www.cpan.org/ for details.
33
35 FastCGI scripts are persistent: one or more copies of the script are
36 started up when the server initializes, and stay around until the
37 server exits or they die a natural death. After performing whatever
38 one-time initialization it needs, the script enters a loop waiting for
39 incoming connections, processing the request, and waiting some more.
40
41 A typical FastCGI script will look like this:
42
43 #!/usr/bin/perl
44 use CGI::Fast;
45 &do_some_initialization();
46 while ($q = new CGI::Fast) {
47 &process_request($q);
48 }
49
50 Each time there's a new request, CGI::Fast returns a CGI object to your
51 loop. The rest of the time your script waits in the call to new().
52 When the server requests that your script be terminated, new() will
53 return undef. You can of course exit earlier if you choose. A new
54 version of the script will be respawned to take its place (this may be
55 necessary in order to avoid Perl memory leaks in long-running scripts).
56
57 CGI.pm's default CGI object mode also works. Just modify the loop this
58 way:
59
60 while (new CGI::Fast) {
61 &process_request;
62 }
63
64 Calls to header(), start_form(), etc. will all operate on the current
65 request.
66
68 See the FastCGI developer's kit documentation for full details. On the
69 Apache server, the following line must be added to srm.conf:
70
71 AddType application/x-httpd-fcgi .fcgi
72
73 FastCGI scripts must end in the extension .fcgi. For each script you
74 install, you must add something like the following to srm.conf:
75
76 FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
77
78 This instructs Apache to launch two copies of file_upload.fcgi at
79 startup time.
80
82 Any script that works correctly as a FastCGI script will also work
83 correctly when installed as a vanilla CGI script. However it will not
84 see any performance benefit.
85
87 FastCGI supports a TCP/IP transport mechanism which allows FastCGI
88 scripts to run external to the webserver, perhaps on a remote machine.
89 To configure the webserver to connect to an external FastCGI server,
90 you would add the following to your srm.conf:
91
92 FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888
93
94 Two environment variables affect how the "CGI::Fast" object is created,
95 allowing "CGI::Fast" to be used as an external FastCGI server. (See
96 "FCGI" documentation for "FCGI::OpenSocket" for more information.)
97
98 FCGI_SOCKET_PATH
99 The address (TCP/IP) or path (UNIX Domain) of the socket the
100 external FastCGI script to which bind an listen for incoming
101 connections from the web server.
102
103 FCGI_LISTEN_QUEUE
104 Maximum length of the queue of pending connections.
105
106 For example:
107
108 #!/usr/local/bin/perl # must be a FastCGI version of perl!
109 use CGI::Fast;
110 &do_some_initialization();
111 $ENV{FCGI_SOCKET_PATH} = "sputnik:8888";
112 $ENV{FCGI_LISTEN_QUEUE} = 100;
113 while ($q = new CGI::Fast) {
114 &process_request($q);
115 }
116
118 I haven't tested this very much.
119
121 Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
122
123 This library is free software; you can redistribute it and/or modify it
124 under the same terms as Perl itself.
125
126 Address bug reports and comments to: lstein@cshl.org
127
129 This section intentionally left blank.
130
132 CGI::Carp, CGI
133
134
135
136perl v5.16.3 2011-11-09 CGI::Fast(3)