NAME

POE::Component::FastCGI - POE FastCGI server

SYNOPSIS

You can use this module with a direct subroutine callback:

  use POE;
  use POE::Component::FastCGI;

  POE::Component::FastCGI->new(
     Port => 1026,
     Handlers => [
        [ '/' => \&default ],
     ]
  );

  sub default {
     my($request) = @_;

     my $response = $request->make_response;
     $response->header("Content-type" => "text/html");
     $response->content("A page");
     $response->send;
  }

  POE::Kernel->run;

and a POE event callback:

  use POE;
  use POE::Component::FastCGI;

  POE::Component::FastCGI->new(
     Port => 1026,
     Handlers => [
        [ '/' => 'poe_event_name' ],
     ]
     Session => 'MAIN',
  );

  sub default {
     my($request) = @_;

     my $response = $request->make_response;
     $response->header("Content-type" => "text/html");
     $response->content("A page");
     $response->send;
  }

DESCRIPTION

Provides a FastCGI (http://www.fastcgi.com/) server for POE.

POE::Component::FastCGI->new([name => value], ...)

Creates a new POE session for the FastCGI server and listens on the specified port.

Parameters Auth (optional) A code reference to run when called as a FastCGI authorizer. Handlers (required) A array reference with a mapping of paths to code references or POE event names. Port (required unless Unix is set) Port number to listen on. Address (requied if Unix is set) Address to listen on. Unix (optional) Listen on UNIX socket given in Address. Session (required if you want to get POE callbacks) Into which session we should post the POE event back.

The call returns a POE session ID. This should be stored, and when application is to be terminated, a 'shutdown' event can be posted to this session. This will terminate the server socket and free resources.

The handlers parameter should be a list of lists defining either regexps of paths to match or absolute paths to code references.

The code references will be passed one parameter, a POE::Component::FastCGI::Request object. To send a response the make_response method should be called which returns a POE::Component::FastCGI::Response object. These objects are subclasses of HTTP::Request and HTTP::Response respectively.

Example: Handlers => [ [ '/page' => \&page ], [ qr!^/(\w+)\.html$! => sub { my $request = shift; my $response = $request->make_response; output_template($request, $response, $1); } ], ]

USING FASTCGI

Many webservers have support for FastCGI. PoCo::FastCGI has been tested on Mac OSX and Linux using lighttpd.

Currently you must run the PoCo::FastCGI script separately to the webserver and then instruct the webserver to connect to it.

Lighttpd configuration example (assuming listening on port 1026):

   $HTTP["host"] == "some.host" {
      fastcgi.server = ( "/" =>
         ( "localhost" => (
            "host" => "127.0.0.1",
            "port" => 1026,
            "check-local" => "disable",
            "docroot" => "/"
            )
         )
      )
   }

With mod_fastcgi on Apache the equivalent directive is FastcgiExternalServer.

MAINTAINER

Chris 'BinGOs' Williams on behalf of the POE community

AUTHOR

Copyright 2005, David Leadbeater http://dgl.cx/contact. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

BUGS

Please let me know.

SEE ALSO

POE::Component::FastCGI::Request, POE::Component::FastCGI::Response, POE::Filter::FastCGI, POE.