The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FCGI::Engine - A flexible engine for running FCGI-based applications

SYNOPSIS

  # in scripts/my_web_app_fcgi.pl
  use strict;
  use warnings;
  
  use FCGI::Engine;
  
  FCGI::Engine->new_with_options(
      handler_class  => 'My::Web::Application',
      handler_method => 'run',
      pre_fork_init  => sub {
          require('my_web_app_startup.pl');
      }
  )->run;

  # run as normal FCGI script
  perl scripts/my_web_app_fcgi.pl

  # run as standalone FCGI server
  perl scripts/my_web_app_fcgi.pl --nproc 10 --pidfile /tmp/my_app.pid \
                                  --listen /tmp/my_app.socket --daemon

IMPORTANT NOTE

This is an early release of this module, it is intended to fill the need for a better set of FastCGI tools. At this point it still lacks good documentation and a few of the bits still need some work. However it is reasonably stable and I am using it actively at $work. If you have any questions about this module feel free to contact me.

The API for FCGI::Engine is probably the only one which will not change (since is really just emulates the Catalyst::Engine::FCGI API), all other modules in this distro are subject to change at this point.

DESCRIPTION

This module helps manage FCGI based web applications by providing a wrapper which handles most of the low-level FCGI details for you. It can run FCGI programs as simple scripts or as full standalone socket based servers who are managed by FCGI::Engine::ProcManager.

The code is largely based (*cough* stolen *cough*) on the Catalyst::Engine::FastCGI module, and provides a command line interface which is compatible with that module. But of course it does not require Catalyst or anything Catalyst related. So you can use this module with your CGI::Application-based web application or any other Random::Web::Framework-based web app.

CAVEAT

This module is *NIX only, it definitely does not work on Windows and I have no intention of making it do so. Sorry.

PARAMETERS

Command Line

This module uses MooseX::Getopt for command line parameter handling and validation.

All parameters are currently optional, but some parameters depend on one another.

--listen -l

This should be a file path where the unix domain socket file should live. If this parameter is specified, then you must also specify a location for the pidfile.

--nproc -n

This should be an integer specifying the number of FCGI processes that FCGI::Engine::ProcManager should start up. The default is 1.

--pidfile -p

This should be a file path where your pidfile should live. This parameter is only used if the listen parameter is specified.

--daemon -d

This is a boolean parameter and has no argument, it is either used or not. It determines if the script should daemonize itself. This parameter only used if the listen parameter is specified.

--manager -m

This allows you to pass the name of a FCGI::ProcManager subclass to use. The default is to use FCGI::Engine::ProcManager, and any value passed to this parameter must be a subclass of FCGI::ProcManager.

Constructor

In addition to the command line parameters, there are a couple parameters that the constuctor expects.

handler_class

This is expected to be a class name, which will be used inside the request loop to dispatch your web application.

handler_method

This is the class method to be called on the handler_class to server as a dispatch entry point to your web application. It will default to handler.

pre_fork_init

This is an optional CODE reference which will be executed prior to the request loop, and in a multi-proc context, prior to any forking (so as to take advantage of OS COW features).

METHODS

listen

Returns the value passed on the command line with --listen. This will return a Path::Class::File object.

is_listening

A predicate used to determine if the --listen parameter was specified.

nproc

Returns the value passed on the command line with --nproc.

pidfile

Returns the value passed on the command line with --pidfile. This will return a Path::Class::File object.

has_pidfile

A predicate used to determine if the --pidfile parameter was specified.

detach

Returns the value passed on the command line with --daemon.

should_detach

A predicate used to determine if the --daemon parameter was specified.

manager

Returns the value passed on the command line with --manager.

Inspection

has_pre_fork_init

A predicate telling you if anything was passed to the pre_fork_init constructor parameter.

Important Stuff

run (%addtional_options)

Call this to start the show.

It passes the %addtional_options arguments to both the pre_fork_init sub and as constructor args to the proc_manager.

Other Stuff

BUILD

This is the Moose BUILD method, it checks some of our parameters to be sure all is sane.

meta

This returns the Moose metaclass assocaited with this class.

SEE ALSO

Catalyst::Engine::FastCGI

I took all the guts of that module and squished them around a bit and stuffed them in here.

MooseX::Getopt
FCGI::ProcManager

I refactored this module and renamed it FCGI::Engine::ProcManager, which is now included in this distro.

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2007-2008 by Infinity Interactive, Inc.

http://www.iinteractive.com

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