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