The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

POE::Component::FastCGI - POE FastCGI server

SYNOPSIS

  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;
  }

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. 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.

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.

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.