[edit] Known Problems

This module is experimental; therefore anything is possible and bugs are likely.

  1. If a Perl module performs protracted operation, (for example DNS lookups, database queries, etc), then the worker process that is running the Perl script is completely tied up for the duration of script. Therefore embedded Perl scripts should be extremely careful to limit themselves to short, predictable operations.
  2. It's possible for Nginx to leak memory if you reload the configuration file (via 'kill -HUP <pid>').

Example:

http {
  perl_modules  perl/lib;
  perl_require  hello.pm;
 
  perl_set  $msie6  '
  sub {
    my $r = shift;
    my $ua = $r->header_in("User-Agent");
    return "" if $ua =~ /Opera/;
    return "1" if $ua =~ / MSIE [6-9] \.\d+/;
    return "";
  }
 ';
 
  server {
    location / {
      perl  hello::handler;
    }
  }
}

perl/lib/hello.pm:

package hello;
use nginx;
 
sub handler {
  my $r = shift;
  $r->send_http_header("text/html");
  return OK if $r->header_only;
 
  $r->print("hello!\n<br/>");
  $r->rflush;
 
  if (-f $r->filename or -d _) {
    $r->print($r->uri, " exists!\n");
  }
 
  return OK;
}
 
1;
__END__

[edit] Directives


Module: HttpPerlModule