FCGI::Async - Module to allow use of FastCGI asynchronously


This module allows a program to respond to FastCGI requests using an asynchronous model. It is based on IO::Async and will fully interact with any program using this base.

 use FCGI::Async;
 use IO::Async::Set::IO_Poll;

 my $fcgi = FCGI::Async->new(
    on_request => sub {
       my ( $fcgi, $req ) = @_;

       # Handle the request here

 my $set = IO::Async::Set::IO_Poll->new();

 $set->add( $fcgi );



$fcgi = FCGI::Async->new( %args )

This function returns a new instance of a FCGI::Async object, containing a master socket to listen on. The constructor returns immediately; it does not make any blocking calls.

The function operates in one of three ways, depending on arguments passed in the %args hash:

  • Listening on an existing socket.

     socket => $socket

    This must be a socket opened in listening mode, derived from IO::Socket, or any other class that handles the fileno and accept methods in a similar way.

  • Creating a new listening socket.

     port => $port

    A new IO::Socket::INET socket will be opened on the given port number. It will listen on all interfaces, from all addresses.

  • Using the socket passed as STDIN from a webserver.

    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, pass neither of the above options.

The %args hash must also contain a CODE reference to a callback function to call when a new FastCGI request arrives

 on_request => sub { ... }


 on_request => \&handler

This will be passed two parameters; the FCGI::Async container object, and a new FCGI::Async::Request object representing the specific request.

 $on_request->( $fcgi, $request )



Paul Evans <>

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 192:

You forgot a '=back' before '=head1'

Around line 196:

=back without =over