8 XSLoader::load(__PACKAGE__, $VERSION);
11 sub FAIL_ACCEPT_ON_INTR () { 1 };
13 sub Request(;***$*$) {
14 my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, FAIL_ACCEPT_ON_INTR);
15 $_[4] = fileno($_[4]) if defined($_[4]) && defined(fileno($_[4]));
16 splice @defaults,0,@_,@_;
24 shift->PRINT(sprintf(shift, @_));
33 my $rs = $/ eq '' ? "\n\n" : $/;
34 my $l = substr $rs, -1;
45 last if $c eq $l and substr($s, -$len) eq $rs;
53 Carp::croak(q/Operation 'OPEN' not supported on FCGI::Stream handle/);
58 Carp::croak(q/Operation 'SEEK' not supported on FCGI::Stream handle/);
63 Carp::croak(q/Operation 'TELL' not supported on FCGI::Stream handle/);
68 Carp::croak(q/Operation 'TIEHANDLE' not supported on FCGI::Stream handle/);
77 FCGI - Fast CGI module
84 my $request = FCGI::Request();
86 while($request->Accept() >= 0) {
87 print("Content-type: text/html\r\n\r\n", ++$count);
98 Creates a request handle. It has the following optional parameters:
102 =item input perl file handle (default: \*STDIN)
104 =item output perl file handle (default: \*STDOUT)
106 =item error perl file handle (default: \*STDERR)
108 These filehandles will be setup to act as input/output/error
109 on successful Accept.
111 =item environment hash reference (default: \%ENV)
113 The hash will be populated with the environment.
115 =item socket (default: 0)
117 Socket to communicate with the server.
118 Can be the result of the OpenSocket function.
119 For the moment, it's the file descriptor of the socket
120 that should be passed. This may change in the future.
122 You should only use your own socket if your program
123 is not started by a process manager such as mod_fastcgi
124 (except for the FastCgiExternalServer case) or cgi-fcgi.
125 If you use the option, you have to let your FastCGI
126 server know which port (and possibly server) your program
128 See remote.pl for an example.
130 =item flags (default: 0)
136 =item FCGI::FAIL_ACCEPT_ON_INTR
138 If set, Accept will fail if interrupted.
139 It not set, it will just keep on waiting.
146 my $req = FCGI::Request;
150 my $in = new IO::Handle;
151 my $out = new IO::Handle;
152 my $err = new IO::Handle;
153 my $req = FCGI::Request($in, $out, $err, \%env);
155 =item FCGI::OpenSocket(path, backlog)
157 Creates a socket suitable to use as an argument to Request.
163 Pathname of socket or colon followed by local tcp port.
164 Note that some systems take file permissions into account
165 on Unix domain sockets, so you'll have to make sure that
166 the server can write to the created file, by changing
167 the umask before the call and/or changing permissions and/or
168 group of the file afterwards.
172 Maximum length of the queue of pending connections.
174 request arrives with the queue full the client may receive
175 an error with an indication of ECONNREFUSED.
179 =item FCGI::CloseSocket(socket)
181 Close a socket opened with OpenSocket.
185 Accepts a connection on $req, attaching the filehandles and
186 populating the environment hash.
187 Returns 0 on success.
188 If a connection has been accepted before, the old
189 one will be finished first.
191 Note that unlike with the old interface, no die and warn
192 handlers are installed by default. This means that if
193 you are not running an sfio enabled perl, any warn or
194 die message will not end up in the server's log by default.
195 It is advised you set up die and warn handlers yourself.
196 FCGI.pm contains an example of die and warn handlers.
200 Finishes accepted connection.
201 Also detaches filehandles.
205 Flushes accepted connection.
209 Temporarily detaches filehandles on an accepted connection.
213 Re-attaches filehandles on an accepted connection.
215 =item $req->LastCall()
217 Tells the library not to accept any more requests on this handle.
218 It should be safe to call this method from signal handlers.
220 Note that this method is still experimental and everything
221 about it, including its name, is subject to change.
223 =item $env = $req->GetEnvironment()
225 Returns the environment parameter passed to FCGI::Request.
227 =item ($in, $out, $err) = $req->GetHandles()
229 Returns the file handle parameters passed to FCGI::Request.
231 =item $isfcgi = $req->IsFastCGI()
233 Returns whether or not the program was run as a FastCGI.
239 FCGI.pm isn't Unicode aware, only characters within the range 0x00-0xFF are
240 supported. Attempts to output strings containing characters above 0xFF results
241 in a exception: (F) C<Wide character in %s>.
243 Users who wants the previous (FCGI.pm <= 0.68) incorrect behavior can disable the
244 exception by using the C<bytes> pragma.
254 Sven Verdoolaege <skimo@kotnet.org>