rewrite documentation of mod_perl as the only persistent backend
[perl/plp/.git] / lib / PLP / FAQ.pod
1 =head1 NAME
2
3 PLP::FAQ - Frequently Asked Questions about PLP
4
5 =head1 FAQ
6
7 =over 10
8
9 =item What does PLP stand for?
10
11 PerlPage. The name used to be HTMPL, but HyperText Markup with Perl Language
12 was too long.
13
14 =item Is PLP hard to install?
15
16 No, it actually is very simple and easy. Quick startup hints are in the PLP main
17 documentation, extensive installation instructions are on the PLP website.
18
19 =item Is Perl code harder than PHP code?
20
21 Yes, it is. But when you get used to Perl, you will probably dislike PHP for
22 the rest of your life. Perl is faster and far more powerful. For both Perl
23 beginners and more advanced Perl coders, PerlMonks is a good Perl forum community.
24 (Please note: PLP is not Perl. Perl is a complete programming language and is
25 not restricted to web based applications. PLP B<uses> Perl, but many people
26 use Perl without PLP.
27
28 =item Can PLP be used with mod_perl?
29
30 Yes. As of 3.00, PLP can be used with mod_perl! And it's very fast!
31
32 =item You seem to promote dirty programming. Can I use strict with PLP?
33
34 PLP can be used for quick-and-dirty hacks in a way similar to PHP. However, it
35 is suitable for larger applications as well. You can use strict if you want.
36 mod_perl Users might like to know that globals are automatically destroyed (as
37 long as you do not switch packages).
38
39 =item How can I make PLP faster?
40
41 With mod_perl or FastCGI, PLP is a lot faster than with CGI.
42 Instead of executing a new perl process for each request, the same interpreter
43 will serve multiple pages.
44
45 =item I already run persistently, can I make my scripts even faster?
46
47 Well, you already have scripts that probably are faster than PHP equivalents,
48 but speed maniacs always want more. Modules are cached, so with a proper module
49 design, you can add a little more speed.
50
51 =item Can I use Perl's CGI module with PLP?
52
53 You certainly can! If you do not want %get and %post and the like, just don't
54 use them. They will be generated on first access, so if you never access them,
55 the hashes are never filled.
56
57 If you want to use CGI.pm's header functions, C<select STDOUT;> first, to break
58 out of PLP's tied C<PLPOUT> filehandle.
59
60 =item Why does C<< <($filename)> >> not work?
61
62 C<< <(...)> >> is a compile-time tag, opposed to C<include()>, which is evaluated
63 at run-time. At compile time, variables are not yet known, and PLP will try to
64 include a file literally called C<$filename>.
65
66     <: $filename = 'foo.inc.plp'; include($filename); :>
67
68 =item Why do my variables not work in my C<include()>d file?
69
70 That is because your variable is lexical (declared with C<my>), and the file is
71 evaluated in its own scope, just as with Perl's built-in C<do> and C<require>.
72 You can pass variables through subroutine parameters or by using globals
73 variables. Another solution is using PLP's C<< <(...)> >> tag.
74
75 =item But why do they work with C<< <()> >> then?
76
77 Because it places the external file is placed inside of the other,
78 B<before> the code is executed (at compile-time).
79
80 =item Why do my C<END> blocks never get executed?
81
82 These blocks are executed when the interpreter stops, which only occurs if you
83 are running as CGI.  To catch the exit of a PLP script, use C<PLP_END> blocks instead.
84 Please note that C<PLP_END> is a normal statement, so you may need a semicolon.
85
86     <html><body>
87     <: PLP_END { :>
88         </body></html>
89     <: } :>
90     contents
91
92 =item Can I disable the error messages?
93
94 You can not disable compile-time errors (syntax errors), but you can disable
95 run-time errors. To do so, set the 0-bit (1) of C<$PLP::DEBUG> off. If you only
96 want error reporting disabled for a single command, use Perl's C<eval BLOCK>
97 function (not C<eval "">, but C<eval {}>, which is not slow or insecure.).
98
99     <: $PLP::DEBUG &= ~1; :>
100
101 =item Can I have my own error messages?
102
103 Yes, you can! Of course, you can not override compile-time errors like syntax
104 errors, but run-time error messages use C<$PLP::ERROR>, which is a reference to a
105 sub that gets two arguments: the error message itself, and an html-encoded
106 version.
107
108     <:
109         $PLP::ERROR = sub {
110             my ($plain, $html) = @_;
111             print '<font color="red">', $html, '</font>';
112         };
113     :>
114
115 =item Is there a way to see the headers that PLP sends?
116
117 There is. Set C<$PLP::DEBUG>'s 1-bit (2), and it will output a plain text header
118 before outputting the other one.
119
120     <: $PLP::DEBUG |= 2; :>
121
122 =back
123
124 =cut
125