expand backend documentation
[perl/plp/.git] / PLP / Backend / FastCGI.pm
1 package PLP::Backend::FastCGI;
2
3 use strict;
4
5 use PLP::Backend::CGI;
6 use FCGI;
7 use base 'PLP::Backend::CGI';
8
9 our $VERSION = '1.01';
10
11 sub import {
12         my $self = shift;
13         my $request = FCGI::Request();
14         $SIG{TERM} = sub {
15                 $request->LastCall();
16         };
17         $SIG{PIPE} = 'IGNORE';
18         while ($request->Accept() >= 0) {
19                 $PLP::use_cache = !defined $ENV{PLP_CACHE} || $ENV{PLP_CACHE}; # before it's clean()ed
20                 delete $ENV{PATH_TRANSLATED};
21                 $self->everything();
22         }
23 }
24
25 1;
26
27 =head1 NAME
28
29 PLP::Backend::FastCGI - FastCGI interface for PLP
30
31 =head1 SYNOPSIS
32
33 =head2 Lighttpd
34
35 Edit the configuration file (usually F</etc/lighttpd/lighttpd.conf>)
36 to enable I<mod_fastcgi> (add/outcomment in server.modules), and add:
37
38     fastcgi.server = (
39         ".plp" => ((
40             "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI",
41             "socket" => "/tmp/fcgi-plp.socket",
42         )),
43     )
44
45 =head2 Apache
46
47 You'll need a dispatch script (F<plp.fcgi> is included with PLP).
48 Example F</foo/bar/plp.fcgi>:
49
50     #!/usr/bin/perl
51     use PLP::Backend::FastCGI;
52
53 Then enable either I<mod_fcgid> (recommended) or I<mod_fastcgi>, and
54 setup F<httpd.conf> (in new installs just create F</etc/apache/conf.d/plp>) with:
55
56     <IfModule mod_fastcgi.c>
57         AddHandler fastcgi-script plp
58         FastCgiWrapper /foo/bar/plp.fcgi
59     </IfModule>
60
61     <IfModule mod_fcgid.c>
62         AddHandler fcgid-script plp
63         FCGIWrapper /foo/bar/plp.fcgi .plp
64     </IfModule>
65
66 =head1 DESCRIPTION
67
68 This is usually the preferred backend, providing persistent processes
69 for speeds comparable to L<mod_perl|PLP::Backend::Apache> and
70 reliability closer to L<CGI|PLP::Backend::CGI>.
71
72 Servers often feature auto-adjusting number of daemons, script timeouts,
73 and occasional restarts.
74
75 =head2 Configuration directives
76
77 PLP behaviour can be configured by setting environment variables.
78
79 =over 16
80
81 =item PLP_CACHE
82
83 Sets caching off if false (0 or empty), on otherwise (true or undefined).
84 When caching, PLP saves your script in memory and doesn't re-read
85 and re-parse it if it hasn't changed. PLP will use more memory,
86 but will also run 50% faster.
87
88 =back
89
90 =head1 AUTHOR
91
92 Mischa POSLAWSKY <perl@shiar.org>
93
94 =head1 SEE ALSO
95
96 L<PLP>, L<PLP::Backend::CGI>, L<FCGI>
97