comparison xml/en/docs/http/ngx_http_perl_module.xml @ 966:95c3c3bbf1ce

Text review.
author Egor Nikitin <yegor.nikitin@gmail.com>
date Wed, 14 Aug 2013 12:03:41 +0400
parents f0e3d07c66d8
children d37892ad69ab
comparison
equal deleted inserted replaced
965:fadccc156188 966:95c3c3bbf1ce
13 rev="2"> 13 rev="2">
14 14
15 <section id="summary"> 15 <section id="summary">
16 16
17 <para> 17 <para>
18 The <literal>ngx_http_perl_module</literal> module allows to implement 18 The <literal>ngx_http_perl_module</literal> module is used to implement
19 location and variable handlers in Perl, and to insert Perl calls into SSI. 19 location and variable handlers in Perl and insert Perl calls into SSI.
20 </para> 20 </para>
21 21
22 <para> 22 <para>
23 This module is not built by default, it should be enabled with the 23 This module is not built by default, it should be enabled with the
24 <literal>--with-http_perl_module</literal> 24 <literal>--with-http_perl_module</literal>
25 configuration parameter. 25 configuration parameter.
26 <note> 26 <note>
27 This module requires Perl version 5.6.1 or higher. 27 This module requires Perl version 5.6.1 or higher.
28 The C compiler should be compatible with that used to build Perl. 28 The C compiler should be compatible with the one used to build Perl.
29 </note> 29 </note>
30 </para> 30 </para>
31 31
32 </section> 32 </section>
33 33
38 The module is experimental, caveat emptor applies. 38 The module is experimental, caveat emptor applies.
39 </para> 39 </para>
40 40
41 <para> 41 <para>
42 In order for Perl to recompile the modified modules during 42 In order for Perl to recompile the modified modules during
43 reconfiguration, it needs to be built with the parameters 43 reconfiguration, it should be built with the
44 <literal>-Dusemultiplicity=yes</literal> or 44 <literal>-Dusemultiplicity=yes</literal> or
45 <literal>-Dusethreads=yes</literal>. 45 <literal>-Dusethreads=yes</literal> parameters.
46 Also, in order for Perl to leak less memory at run time, 46 Also, to make Perl leak less memory at run time,
47 it needs to be built with the 47 it should be built with the
48 <literal>-Dusemymalloc=no</literal> parameter. 48 <literal>-Dusemymalloc=no</literal> parameter.
49 To check the values of these parameters in an already built 49 To check the values of these parameters in an already built
50 Perl (preferred values are specified in the example), run: 50 Perl (preferred values are specified in the example), run:
51 <example> 51 <example>
52 $ perl -V:usemultiplicity -V:usemymalloc 52 $ perl -V:usemultiplicity -V:usemymalloc
54 usemymalloc='n'; 54 usemymalloc='n';
55 </example> 55 </example>
56 </para> 56 </para>
57 57
58 <para> 58 <para>
59 Note that after rebuilding Perl with the new parameters 59 Note that after rebuilding Perl with the new
60 <literal>-Dusemultiplicity=yes</literal> or 60 <literal>-Dusemultiplicity=yes</literal> or
61 <literal>-Dusethreads=yes</literal>, 61 <literal>-Dusethreads=yes</literal> parameters,
62 all binary Perl modules will have to be rebuilt as well — 62 all binary Perl modules will have to be rebuilt as well —
63 they will just stop working with the new Perl. 63 they will just stop working with the new Perl.
64 </para> 64 </para>
65 65
66 <para> 66 <para>
67 It is possible for the main process and then worker processes 67 There is a possibility that the main process and then worker processes will
68 to grow in size after every reconfiguration. 68 grow in size after every reconfiguration.
69 If the main process grows to an unacceptable size, the 69 If the main process grows to an unacceptable size, the
70 <link doc="../control.xml" id="upgrade">live upgrade</link> 70 <link doc="../control.xml" id="upgrade">live upgrade</link>
71 procedure can be applied without changing an executable file. 71 procedure can be applied without changing the executable file.
72 </para> 72 </para>
73 73
74 <para> 74 <para>
75 While a Perl module performs long term operation, for example, resolves 75 While the Perl module is performing a long-running operation, such as
76 a domain name, connects to another server, queries a database, 76 resolving a domain name, connecting to another server, or querying a database,
77 other requests assigned to this worker process will not be processed. 77 other requests assigned to the current worker process will not be processed.
78 It is thus recommended to limit the work done to operations 78 It is thus recommended to perform only such operations
79 that have predictable and short execution time, for example, 79 that have predictable and short execution time, such as
80 access local file system. 80 accessing the local file system.
81 </para> 81 </para>
82 82
83 <para> 83 <para>
84 The below mentioned issues only affect versions of nginx before 0.6.22. 84 The issues mentioned below affect only the nginx versions before 0.6.22.
85 85
86 <note> 86 <note>
87 Data returned by the <literal>$r</literal> request object methods 87 The <literal>$r</literal> request object methods return
88 only has a text value, and the value itself is stored in memory 88 data only as a string value, and the value itself is stored in memory
89 allocated by nginx from its own pools, not by Perl. 89 allocated by nginx from its own pools, not by Perl.
90 This allows to reduce the number of copy operations involved in 90 This helps to reduce the number of copy operations involved in
91 most cases, however it can lead to errors in some cases. 91 most cases; however it can lead to errors in some cases.
92 For example, a worker process trying to use such a data in the 92 For example, a worker process trying to use such data in the
93 numeric context will terminate with an error (FreeBSD): 93 numeric context will terminate with an error (FreeBSD):
94 <example> 94 <example>
95 nginx in realloc(): warning: pointer to wrong page 95 nginx in realloc(): warning: pointer to wrong page
96 Out of memory! 96 Out of memory!
97 Callback called exit. 97 Callback called exit.
100 <example> 100 <example>
101 *** glibc detected *** realloc(): invalid pointer: ... *** 101 *** glibc detected *** realloc(): invalid pointer: ... ***
102 Out of memory! 102 Out of memory!
103 Callback called exit. 103 Callback called exit.
104 </example> 104 </example>
105 The workaround is simple — a method’s value should be assigned 105 The workaround is simple — the method’s value should be assigned
106 to a variable. 106 to a variable.
107 For example, the following code 107 For example, the following code
108 <example> 108 <example>
109 my $i = $r->variable('counter') + 1; 109 my $i = $r->variable('counter') + 1;
110 </example> 110 </example>
119 Since most strings inside nginx are stored without a terminating null 119 Since most strings inside nginx are stored without a terminating null
120 character, they are similarly returned by the <literal>$r</literal> request 120 character, they are similarly returned by the <literal>$r</literal> request
121 object methods (except for the <literal>$r->filename</literal> and 121 object methods (except for the <literal>$r->filename</literal> and
122 <literal>$r->request_body_file</literal> methods). 122 <literal>$r->request_body_file</literal> methods).
123 Thus, such values cannot be used as filenames and the likes. 123 Thus, such values cannot be used as filenames and the likes.
124 The workaround is similar to a previous case — the value should either be 124 The workaround is similar to the previous case — the value should either be
125 assigned to a variable (this results in data copying that in turn adds 125 assigned to a variable (this results in data copying and adding of
126 the necessary null character) or used in an expression, for example: 126 the necessary null character) or used in an expression, for example:
127 <example> 127 <example>
128 open FILE, '/path/' . $r->variable('name'); 128 open FILE, '/path/' . $r->variable('name');
129 </example> 129 </example>
130 </note> 130 </note>
201 <default/> 201 <default/>
202 <context>location</context> 202 <context>location</context>
203 <context>limit_except</context> 203 <context>limit_except</context>
204 204
205 <para> 205 <para>
206 Installs a Perl handler for the given location. 206 Sets a Perl handler for the given location.
207 </para> 207 </para>
208 208
209 </directive> 209 </directive>
210 210
211 211
227 <context>http</context> 227 <context>http</context>
228 228
229 <para> 229 <para>
230 Defines the name of a module that will be loaded during each 230 Defines the name of a module that will be loaded during each
231 reconfiguration. 231 reconfiguration.
232 There could be several <literal>perl_require</literal> directives. 232 Several <literal>perl_require</literal> directives can be present.
233 </para> 233 </para>
234 234
235 </directive> 235 </directive>
236 236
237 237
282 <tag-name> 282 <tag-name>
283 <literal>$r->has_request_body(<value>handler</value>)</literal> 283 <literal>$r->has_request_body(<value>handler</value>)</literal>
284 </tag-name> 284 </tag-name>
285 <tag-desc> 285 <tag-desc>
286 returns 0 if there is no body in a request. 286 returns 0 if there is no body in a request.
287 If there is a body, the specified handler is installed 287 If there is a body, the specified handler is set for the request
288 and 1 is returned. 288 and 1 is returned.
289 After reading the request body, nginx will call the installed handler. 289 After reading the request body, nginx will call the specified handler.
290 Note that the handler function should be passed by reference. 290 Note that the handler function should be passed by reference.
291 Example: 291 Example:
292 <example> 292 <example>
293 package hello; 293 package hello;
294 294
330 enables the use of byte ranges when sending responses. 330 enables the use of byte ranges when sending responses.
331 </tag-desc> 331 </tag-desc>
332 332
333 <tag-name><literal>$r->discard_request_body</literal></tag-name> 333 <tag-name><literal>$r->discard_request_body</literal></tag-name>
334 <tag-desc> 334 <tag-desc>
335 instructs nginx to discard a request body. 335 instructs nginx to discard the request body.
336 </tag-desc> 336 </tag-desc>
337 337
338 <tag-name><literal>$r->header_in(<value>field</value>)</literal></tag-name> 338 <tag-name><literal>$r->header_in(<value>field</value>)</literal></tag-name>
339 <tag-desc> 339 <tag-desc>
340 returns value of the specified client request header field. 340 returns the value of the specified client request header field.
341 </tag-desc> 341 </tag-desc>
342 342
343 <tag-name><literal>$r->header_only</literal></tag-name> 343 <tag-name><literal>$r->header_only</literal></tag-name>
344 <tag-desc> 344 <tag-desc>
345 determines should the whole response or only its header be sent to a client. 345 determines whether the whole response or only its header should be sent to
346 the client.
346 </tag-desc> 347 </tag-desc>
347 348
348 <tag-name> 349 <tag-name>
349 <literal>$r->header_out(<value>field</value>, 350 <literal>$r->header_out(<value>field</value>,
350 <value>value</value>)</literal> 351 <value>value</value>)</literal>
356 <tag-name> 357 <tag-name>
357 <literal>$r->internal_redirect(<value>uri</value>)</literal> 358 <literal>$r->internal_redirect(<value>uri</value>)</literal>
358 </tag-name> 359 </tag-name>
359 <tag-desc> 360 <tag-desc>
360 does an internal redirect to the specified <value>uri</value>. 361 does an internal redirect to the specified <value>uri</value>.
361 An actual redirect happens after the Perl handler has completed. 362 An actual redirect happens after the Perl handler execution is completed.
362 <note> 363 <note>
363 Redirections to named locations are not currently supported. 364 Redirections to named locations are currently not supported.
364 </note> 365 </note>
365 </tag-desc> 366 </tag-desc>
366 367
367 <tag-name><literal>$r->log_error(<value>errno</value>, 368 <tag-name><literal>$r->log_error(<value>errno</value>,
368 <value>message</value>)</literal></tag-name> 369 <value>message</value>)</literal></tag-name>
378 passes data to a client. 379 passes data to a client.
379 </tag-desc> 380 </tag-desc>
380 381
381 <tag-name><literal>$r->request_body</literal></tag-name> 382 <tag-name><literal>$r->request_body</literal></tag-name>
382 <tag-desc> 383 <tag-desc>
383 returns a client request body if it was not 384 returns the client request body if it has not been
384 written to a temporary file. 385 written to a temporary file.
385 To ensure that a client request body is in memory, 386 To ensure that the client request body is in memory,
386 its size should be limited with 387 its size should be limited by
387 <link doc="ngx_http_core_module.xml" id="client_max_body_size"/>, 388 <link doc="ngx_http_core_module.xml" id="client_max_body_size"/>,
388 and a sufficient buffer size should be set with 389 and a sufficient buffer size should be set using
389 <link doc="ngx_http_core_module.xml" id="client_body_buffer_size"/>. 390 <link doc="ngx_http_core_module.xml" id="client_body_buffer_size"/>.
390 </tag-desc> 391 </tag-desc>
391 392
392 <tag-name><literal>$r->request_body_file</literal></tag-name> 393 <tag-name><literal>$r->request_body_file</literal></tag-name>
393 <tag-desc> 394 <tag-desc>
394 returns the name of a file with the client request body. 395 returns the name of the file with the client request body.
395 At the end of processing, the file needs to be removed. 396 After the processing, the file should be removed.
396 To always write a request body to a file, 397 To always write a request body to a file,
397 <link doc="ngx_http_core_module.xml" id="client_body_in_file_only"/> 398 <link doc="ngx_http_core_module.xml" id="client_body_in_file_only"/>
398 needs to be enabled. 399 should be enabled.
399 </tag-desc> 400 </tag-desc>
400 401
401 <tag-name><literal>$r->request_method</literal></tag-name> 402 <tag-name><literal>$r->request_method</literal></tag-name>
402 <tag-desc> 403 <tag-desc>
403 returns client request HTTP method. 404 returns the client request HTTP method.
404 </tag-desc> 405 </tag-desc>
405 406
406 <tag-name><literal>$r->remote_addr</literal></tag-name> 407 <tag-name><literal>$r->remote_addr</literal></tag-name>
407 <tag-desc> 408 <tag-desc>
408 returns client IP address. 409 returns the client IP address.
409 </tag-desc> 410 </tag-desc>
410 411
411 <tag-name><literal>$r->flush</literal></tag-name> 412 <tag-name><literal>$r->flush</literal></tag-name>
412 <tag-desc> 413 <tag-desc>
413 immediately sends data to a client. 414 immediately sends data to the client.
414 </tag-desc> 415 </tag-desc>
415 416
416 <tag-name> 417 <tag-name>
417 <literal>$r->sendfile(<value>name</value>[, 418 <literal>$r->sendfile(<value>name</value>[,
418 <value>offset</value>[, 419 <value>offset</value>[,
419 <value>length</value>]])</literal> 420 <value>length</value>]])</literal>
420 </tag-name> 421 </tag-name>
421 <tag-desc> 422 <tag-desc>
422 sends the specified file content to a client. 423 sends the specified file content to the client.
423 Optional parameters 424 Optional parameters
424 specify an initial offset and length of data to be transmitted. 425 specify the initial offset and length of the data to be transmitted.
425 The actual data transmission happens after the Perl handler 426 The actual data transmission happens after the Perl handler
426 has completed. 427 has completed.
427 </tag-desc> 428 </tag-desc>
428 429
429 <tag-name> 430 <tag-name>
430 <literal>$r->send_http_header([<value>type</value>])</literal> 431 <literal>$r->send_http_header([<value>type</value>])</literal>
431 </tag-name> 432 </tag-name>
432 <tag-desc> 433 <tag-desc>
433 sends the response header to a client. 434 sends the response header to the client.
434 An optional <value>type</value> parameter sets the value of 435 The optional <value>type</value> parameter sets the value of
435 the <header>Content-Type</header> response header field. 436 the <header>Content-Type</header> response header field.
436 If the value is an empty string, the <header>Content-Type</header> 437 If the value is an empty string, the <header>Content-Type</header>
437 header field will not be passed. 438 header field will not be sent.
438 </tag-desc> 439 </tag-desc>
439 440
440 <tag-name><literal>$r->status(<value>code</value>)</literal></tag-name> 441 <tag-name><literal>$r->status(<value>code</value>)</literal></tag-name>
441 <tag-desc> 442 <tag-desc>
442 sets a response code. 443 sets a response code.
498 <tag-name> 499 <tag-name>
499 <literal>$r->variable(<value>name</value>[, 500 <literal>$r->variable(<value>name</value>[,
500 <value>value</value>])</literal> 501 <value>value</value>])</literal>
501 </tag-name> 502 </tag-name>
502 <tag-desc> 503 <tag-desc>
503 returns or sets a value of the specified variable. 504 returns or sets the value of the specified variable.
504 Variables are local to each request. 505 Variables are local to each request.
505 </tag-desc> 506 </tag-desc>
506 507
507 </list> 508 </list>
508 </para> 509 </para>