FCGI::Async - use FastCGI with IO::Async
FCGI::Async
NOTE: The constructor API of this module has changed since version 0.13!
use FCGI::Async; use IO::Async::Loop; my $loop = IO::Async::Loop->new(); my $fcgi = FCGI::Async->new( loop => $loop, service => 1234, on_request => sub { my ( $fcgi, $req ) = @_; # Handle the request here } ); $loop->loop_forever;
Or
my $fcgi = FCGI::Async->new( on_request => ... ); my $loop = ... $loop->add( $fcgi ); $fcgi->listen( service => 1234 );
This module allows a program to respond asynchronously to FastCGI requests, as part of a program based on IO::Async. An object in this class represents a single FastCGI responder that the webserver is configured to communicate with. It can handle multiple outstanding requests at a time, responding to each as data is provided by the program. Individual outstanding requests that have been started but not yet finished, are represented by instances of FCGI::Async::Request.
This function returns a new instance of a FCGI::Async object.
If either a handle or service argument are passed to the constructor, then the newly-created object is added to the given IO::Async::Loop, then the listen method is invoked, passing the entire %args hash to it. For more detail, see the listen method below.
handle
service
IO::Async::Loop
listen
%args
If either of the above arguments are given, then a IO::Async::Loop must also be provided:
A reference to the IO::Async::Loop which will contain the listening sockets.
The following named parameters may be passed to new or configure:
new
configure
Reference to a handler to call when a new FastCGI request is received. It will be invoked as
$on_request->( $fcgi, $request )
where $request will be a new FCGI::Async::Request object.
$request
Sets the default encoding used by all new requests. If not supplied then UTF-8 will apply.
UTF-8
Start listening for connections on a socket, creating it first if necessary.
This method may be called in either of the following ways. To listen on an existing socket filehandle:
An IO handle referring to a listen-mode socket. This is now deprecated; use the handle key to the new or configure methods instead.
Or, to create the listening socket or sockets:
Port number or service name to listen on.
Optional. If supplied, the hostname will be resolved into a set of addresses, and one listening socket will be created for each address. If not, then all available addresses will be used.
This method may also require on_listen_error or on_resolve_error callbacks for error handling - see IO::Async::Listener for more detail.
on_listen_error
on_resolve_error
The FCGI_GET_VALUES FastCGI request can enquire of the responder the maximum number of connections or requests it can support. Because this module puts no fundamental limit on these values, it will return some arbitrary numbers. These are given in package variables:
FCGI_GET_VALUES
$FCGI::Async::MAX_CONNS = 1024; $FCGI::Async::MAX_REQS = 1024;
These variables are provided in case the containing application wishes to make the library return different values in the request. These values are not actually used by the library, other than to fill in the values in response of FCGI_GET_VALUES.
When running a local FastCGI responder, the webserver will create a new INET socket connected to the script's STDIN file handle. To use the socket in this case, it should be passed as the handle argument.
CGI::Fast - Fast CGI drop-in replacement of CGI; single-threaded, blocking mode.
http://hoohoo.ncsa.uiuc.edu/cgi/interface.html - The Common Gateway Interface Specification
http://www.fastcgi.com/devkit/doc/fcgi-spec.html - FastCGI Specification
Paul Evans <leonerd@leonerd.org.uk>
To install FCGI::Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FCGI::Async
CPAN shell
perl -MCPAN -e shell install FCGI::Async
For more information on module installation, please visit the detailed CPAN module installation guide.