package PLP::Backend::FastCGI;

use strict;

use PLP::Backend::CGI;
use FCGI;
use base 'PLP::Backend::CGI';

our $VERSION = '1.01';

sub import {
	my $self = shift;
	my $request = FCGI::Request();
	$SIG{TERM} = sub {
		$request->LastCall();
	};
	$SIG{PIPE} = 'IGNORE';
	while ($request->Accept() >= 0) {
		$PLP::use_cache = !defined $ENV{PLP_CACHE} || $ENV{PLP_CACHE}; # before it's clean()ed
		delete $ENV{PATH_TRANSLATED};
		$self->everything();
	}
}

1;

=head1 NAME

PLP::Backend::FastCGI - FastCGI interface for PLP

=head1 SYNOPSIS

=head2 Lighttpd

Edit the configuration file (usually F</etc/lighttpd/lighttpd.conf>)
to enable I<mod_fastcgi> (add/outcomment in server.modules), and add:

    fastcgi.server = (
        ".plp" => ((
            "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI",
            "socket" => "/tmp/fcgi-plp.socket",
        )),
    )

=head2 Apache

You'll need a dispatch script (F<plp.fcgi> is included with PLP).
Example F</foo/bar/plp.fcgi>:

    #!/usr/bin/perl
    use PLP::Backend::FastCGI;

Then enable either I<mod_fastcgi> or I<mod_fcgid>, and setup F<httpd.conf>
(often just create a F</etc/apache2/conf.d/plp>) with:

    <IfModule mod_fastcgi.c>
        AddHandler fastcgi-script plp
        FastCgiWrapper /foo/bar/plp.fcgi
    </IfModule>

    <IfModule mod_fcgid.c>
        AddHandler fcgid-script plp
        FCGIWrapper /foo/bar/plp.fcgi .plp
    </IfModule>

=head1 AUTHOR

Mischa POSLAWSKY <perl@shiar.org>

=head1 SEE ALSO

L<PLP>, L<PLP::Backend::CGI>, L<FCGI>

