2 use ExtUtils::MakeMaker;
6 print "Generating FCGI.pm\n";
8 # $Id: FCGI.PL,v 1.37 2002/12/15 20:02:48 skimo Exp $
15 @ISA = qw(Exporter DynaLoader);
16 # Items to export into callers namespace by default. Note: do not export
17 # names by default without a very good reason. Use EXPORT_OK instead.
18 # Do not simply export all your public functions/methods/constants.
25 print OUT '$VERSION = q{'.MM->parse_version('version.pm')."};\n\n";
27 print OUT "bootstrap FCGI;\n";
29 print OUT '$VERSION = eval $VERSION;';
31 print OUT while <DATA>;
35 # Preloaded methods go here.
37 # Autoload methods go after __END__, and are processed by the autosplit program.
39 *FAIL_ACCEPT_ON_INTR = sub() { 1 };
41 sub Request(;***$*$) {
42 my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, FAIL_ACCEPT_ON_INTR());
43 $_[4] = fileno($_[4]) if defined($_[4]) && defined(fileno($_[4]));
44 splice @defaults,0,@_,@_;
51 shift->PRINT(sprintf(shift, @_));
60 my $rs = $/ eq '' ? "\n\n" : $/;
61 my $l = substr $rs, -1;
72 last if $c eq $l and substr($s, -$len) eq $rs;
81 return open($_[0], $_[1]);
84 eval("$rc = open($_[0], $_[1], $_[2])");
90 # Some things (e.g. IPC::Run) use fileno to determine if a filehandle is open,
91 # so we return a defined, but meaningless value. (-1 being the error return
92 # value from the syscall in c, meaning it can never be a valid fd no)
93 # Probably a better alternative would be to return the fcgi stream fd.
102 FCGI - Fast CGI module
109 my $request = FCGI::Request();
111 while($request->Accept() >= 0) {
112 print("Content-type: text/html\r\n\r\n", ++$count);
123 Creates a request handle. It has the following optional parameters:
127 =item input perl file handle (default: \*STDIN)
129 =item output perl file handle (default: \*STDOUT)
131 =item error perl file handle (default: \*STDERR)
133 These filehandles will be setup to act as input/output/error
134 on successful Accept.
136 =item environment hash reference (default: \%ENV)
138 The hash will be populated with the environment.
140 =item socket (default: 0)
142 Socket to communicate with the server.
143 Can be the result of the OpenSocket function.
144 For the moment, it's the file descriptor of the socket
145 that should be passed. This may change in the future.
147 You should only use your own socket if your program
148 is not started by a process manager such as mod_fastcgi
149 (except for the FastCgiExternalServer case) or cgi-fcgi.
150 If you use the option, you have to let your FastCGI
151 server know which port (and possibly server) your program
153 See remote.pl for an example.
155 =item flags (default: 0)
161 =item FCGI::FAIL_ACCEPT_ON_INTR
163 If set, Accept will fail if interrupted.
164 It not set, it will just keep on waiting.
171 my $req = FCGI::Request;
175 my $in = new IO::Handle;
176 my $out = new IO::Handle;
177 my $err = new IO::Handle;
178 my $req = FCGI::Request($in, $out, $err, \%env);
180 =item FCGI::OpenSocket(path, backlog)
182 Creates a socket suitable to use as an argument to Request.
188 Pathname of socket or colon followed by local tcp port.
189 Note that some systems take file permissions into account
190 on Unix domain sockets, so you'll have to make sure that
191 the server can write to the created file, by changing
192 the umask before the call and/or changing permissions and/or
193 group of the file afterwards.
197 Maximum length of the queue of pending connections.
199 request arrives with the queue full the client may receive
200 an error with an indication of ECONNREFUSED.
204 =item FCGI::CloseSocket(socket)
206 Close a socket opened with OpenSocket.
210 Accepts a connection on $req, attaching the filehandles and
211 populating the environment hash.
212 Returns 0 on success.
213 If a connection has been accepted before, the old
214 one will be finished first.
216 Note that unlike with the old interface, no die and warn
217 handlers are installed by default. This means that if
218 you are not running an sfio enabled perl, any warn or
219 die message will not end up in the server's log by default.
220 It is advised you set up die and warn handlers yourself.
221 FCGI.pm contains an example of die and warn handlers.
225 Finishes accepted connection.
226 Also detaches filehandles.
230 Flushes accepted connection.
234 Temporarily detaches filehandles on an accepted connection.
238 Re-attaches filehandles on an accepted connection.
240 =item $req->LastCall()
242 Tells the library not to accept any more requests on this handle.
243 It should be safe to call this method from signal handlers.
245 Note that this method is still experimental and everything
246 about it, including its name, is subject to change.
248 =item $env = $req->GetEnvironment()
250 Returns the environment parameter passed to FCGI::Request.
252 =item ($in, $out, $err) = $req->GetHandles()
254 Returns the file handle parameters passed to FCGI::Request.
256 =item $isfcgi = $req->IsFastCGI()
258 Returns whether or not the program was run as a FastCGI.
264 FCGI.pm isn't Unicode aware, only characters within the range 0x00-0xFF are
265 supported. Attempts to output strings containing characters above 0xFF results
266 in a exception: (F) C<Wide character in %s>.
268 Users who wants the previous (FCGI.pm <= 0.68) incorrect behavior can disable the
269 exception by using the C<bytes> pragma.
279 Sven Verdoolaege <skimo@kotnet.org>