stas        02/04/25 18:43:11

  Modified:    src/start/tips config.pod favicon.pod handler.pod
                        logging.pod registry.pod
  Log:
  apply styles, indentation and markup as explained in admin/style.pod
  
  Revision  Changes    Path
  1.2       +26 -24    modperl-docs/src/start/tips/config.pod
  
  Index: config.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/start/tips/config.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- config.pod        25 Apr 2002 07:01:02 -0000      1.1
  +++ config.pod        26 Apr 2002 01:43:11 -0000      1.2
  @@ -4,34 +4,36 @@
   
   =head1  Configure virtual hosts
   
  -With mod_perl, Perl code can be embedded directly in the Apache 
configuration file.
  -Perl in httpd.conf is commonly used to dynamically configure Apache, but 
anything from
  -URL translation to content generation can be accomplished directly in the 
configuation file.
  +With mod_perl, Perl code can be embedded directly in the Apache
  +configuration file.  Perl in httpd.conf is commonly used to
  +dynamically configure Apache, but anything from URL translation to
  +content generation can be accomplished directly in the configuation
  +file.
   
  -This example reads configuration settings from a text file and configures 
Apache's
  -virtual hosts.
  +This example reads configuration settings from a text file and
  +configures Apache's virtual hosts.
   
  -The httpd.conf setup:
  +The I<httpd.conf> setup:
   
  -    NameVirtualHost 192.168.0.1:80
  -    <Perl>
  -        open(HOSTS,'/etc/apache/vhosts.txt')
  -            or die "Failed to open vhosts.txt: $!";
  -    
  -        while (<HOSTS>) {
  -            my %config;  
  -            my @params = qw/ServerName DocumentRoot ErrorLog TransferLog 
ServerAdmin/;
  -            @config{ @params } = split /\t/;
  -            $config{Directory}{$config{DocumentRoot}} = { Allow => 'from 
all'};
  -              
  -            push @{$VirtualHost{'192.168.0.1:80'}}, \%config;
  -        }
  -        close HOSTS;
  -        
  -    </Perl>
  +  NameVirtualHost 192.168.0.1:80
  +  <Perl>
  +      open HOSTS, '/etc/apache/vhosts.txt'
  +          or die "Failed to open vhosts.txt: $!";
  +  
  +      while (<HOSTS>) {
  +          my %config;
  +          my @params = qw/ServerName DocumentRoot ErrorLog TransferLog 
ServerAdmin/;
  +          @config{ @params } = split /\t/;
  +          $config{ Directory }{ $config{DocumentRoot} } = { Allow => 'from 
all' };
  +  
  +          push @{ $VirtualHost{'192.168.0.1:80'} }, \%config;
  +      }
  +      close HOSTS;
  +  
  +  </Perl>
   
  -See L<The Guide|guide::config/Apache_Configuration_in_Perl>
  -for other examples of configuring Apache with mod_perl.
  +See L<The Guide|guide::config/Apache_Configuration_in_Perl> for other
  +examples of configuring Apache with mod_perl.
   
   =for html
   <a class="more" href="../index.html#config">&#171&nbsp;back</a>
  
  
  
  1.2       +28 -24    modperl-docs/src/start/tips/favicon.pod
  
  Index: favicon.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/start/tips/favicon.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- favicon.pod       25 Apr 2002 07:01:02 -0000      1.1
  +++ favicon.pod       26 Apr 2002 01:43:11 -0000      1.2
  @@ -4,35 +4,39 @@
   
   =head1 Using mod_perl to rewrite URLs
   
  -Anyone that's looked at web logs will quickly see the usefulness of this 
little
  -mod_perl script.  It catches all requests for favicon.ico and rewrites the 
request
  -to point to a vaild location.  No more logs full of 404 errors.
  +Anyone that's looked at web logs will quickly see the usefulness of
  +this little mod_perl script.  It catches all requests for
  +I<favicon.ico> and rewrites the request to point to a vaild location.
  +No more logs full of 404 errors.
  +
  +This example is adapted from the L<mod_perl Devekioer's
  +Cookbook|http://modperlcookbook.com>, chapter 12.
  +
  +  file:Cookbook/Favicon.pm
  +  ------------------------
  +  package Cookbook::Favicon;
  +  
  +  use Apache::Constants qw(DECLINED);
  +  use strict;
  +  
  +  sub handler {
  +      my $r = shift;
  +  
  +      $r->uri('/images/favicon.ico')
  +          if $r->uri =~ m!/favicon\.ico$!
  +  
  +      return DECLINED;
  +  }
  +  1;
   
  -This example is adapted from the L<mod_perl Devekioer's 
Cookbook|http://modperlcookbook.com>, chapter 12.
  -
  -    package Cookbook::Favicon;
  -    
  -    use Apache::Constants qw(DECLINED);
  -    use strict;
  -    
  -    sub handler {
  -        my $r = shift;
  -
  -        $r->uri('/images/favicon.ico')
  -            if $r->uri =~ m!/favicon\.ico$!
  -        
  -        return DECLINED;
  -    }
  -    1;
  -
  -And configure in F<httpd.conf> with:
  +And configure in I<httpd.conf> with:
   
       PerlModule Cookbook::Favicon
       PerlTransHandler Cookbook::Favicon
   
  -Although this example could easily be accomplished with Apache's mod_rewrite 
module,
  -this example demonstrates how easy it is to rewrite URLs programatically, 
using the
  -power of Perl.
  +Although this example could easily be accomplished with Apache's
  +mod_rewrite module, this example demonstrates how easy it is to
  +rewrite URLs programatically, using the power of Perl.
   
   =for html
   <a class="more" href="../index.html#handler">&#171&nbsp;back</a>
  
  
  
  1.3       +39 -33    modperl-docs/src/start/tips/handler.pod
  
  Index: handler.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/start/tips/handler.pod,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- handler.pod       25 Apr 2002 21:45:19 -0000      1.2
  +++ handler.pod       26 Apr 2002 01:43:11 -0000      1.3
  @@ -4,43 +4,49 @@
   
   =head1 Creating a content handler with mod_perl 1.x
   
  -Handlers are simply perl subroutines called by the server at various stages 
of the HTTP request cycle.
  -A content handler is a subroutine that is called by the response phase.  
Handlers, are 
  -typically created as a perl modules, separate files store in a library, and 
accessable via perl's @INC array.
  +Handlers are simply perl subroutines called by the server at various
  +stages of the HTTP request cycle.  A content handler is a subroutine
  +that is called by the response phase.  Handlers, are typically created
  +as a perl modules, separate files store in a library, and accessable
  +via perl's C<@INC> array.
  +
  +For example, here's an example that returns a greeting and the current
  +local time.
  +
  +  file:My/Greeting.pm
  +  -------------------
  +  package My::Greeting;
  +  use strict;
  +  
  +  sub handler {
  +      my $r = shift;
  +      my $now = scalar localtime;
  +      my $server_name = $r->server->server_hostname;
  +  
  +      $r->send_http_header('text/plain');
  +  
  +      print <<EOT;
  +          Thanks for visiting $server_name.
  +          The local time is $now.
  +      EOT
  +  
  +      return Apache::Constants::OK;
  +  }
  +  1; # modules must return true
   
  -For example, here's an example that returns a greeting and the current local 
time.
   
  -    package My::Greeting;
  -        use strict;
  -  
  -        sub handler {
  -            my $r = shift;
  -            my $now = scalar localtime;
  -            my $server_name = $r->server->server_hostname;
  -
  -            $r->send_http_header('text/plain');
  -        
  -            print <<EOT;
  -                Thanks for visiting $server_name.
  -                The local time is $now
  -        EOT
  -            return Apache::Constants::OK;
  -        }
  -        1; # modules must return true
  -
  -
  -Save the above as a file file in your perl library (e.g. My/Greeting.pm).
  -Now, to return the above greeting when the URL /hello is visited on your 
server:
  -
  -    <location /hello>
  -        SetHandler perl-script
  -        PerlHandler My::Greeting
  -    </location>
  +Save the above as a file file in your perl library
  +(e.g. I<My/Greeting.pm>a).  Now, to return the above greeting when the
  +URL I</hello> is visited on your server:
  +
  +  <location /hello>
  +      SetHandler perl-script
  +      PerlHandler My::Greeting
  +  </location>
   
   For a more in-depth explanation of creating mod_perl handlers see
  -L<Documentation|"../../docs/index.html">.
  -The L<mod_perl Guide|"../../docs/1.0/guide/index.html"> is also recommended
  -reading.
  +L<Documentation|"../../docs/index.html">.  The L<mod_perl
  +Guide|"../../docs/1.0/guide/index.html"> is also recommended reading.
   
   =for html
   <a class="more" href="../index.html#handler">&#171&nbsp;back</a>
  
  
  
  1.2       +41 -38    modperl-docs/src/start/tips/logging.pod
  
  Index: logging.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/start/tips/logging.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- logging.pod       25 Apr 2002 07:01:02 -0000      1.1
  +++ logging.pod       26 Apr 2002 01:43:11 -0000      1.2
  @@ -4,44 +4,47 @@
   
   =head1 Creating a PerlLogHandler
   
  -Every request phase can be controlled using mod_perl.  Here's an example
  -of a PerlLogHandler.  The PerlLogHandler is one of the last phases of the 
request
  -cycle.
  -
  -This example sends mail when a request is made to the /private section of 
your
  -web space.  A more common use of a PerlLogHandler might be to track hits on a
  -specific set of URLs, or to write logging data to a relational database.
  -
  -    package My::Notify;
  -    use strict;
  -    use Apache::Constants(':common');
  -
  -    use Mail::Send;
  -
  -    sub handler {
  -        my $r = shift;
  -
  -        my $email = $r->server->server_admin || return DECLINED;
  -
  -        my $mail = Mail::Send->new(
  -            To      => $email,
  -            Subject => "mod_perl Notification",
  -        );
  -        my $file = $r->filename;
  -        my $fh = $mail->open;
  -        $fh->print("File '$file' was accessed");
  -        $fh->close;
  -
  -        return DECLINED; # let apache write to the lot
  -    }
  -    1; # modules must return true
  -
  -The httpd.conf setup:
  -
  -    <location /private>
  -        SetHandler perl-script
  -        PerlLogHandler My::Notify
  -    </location>
  +Every request phase can be controlled using mod_perl.  Here's an
  +example of a C<PerlLogHandler>.  The C<PerlLogHandler> is one of the
  +last phases of the request cycle.
  +
  +This example sends mail when a request is made to the /private section
  +of your web space.  A more common use of a C<PerlLogHandler> might be
  +to track hits on a specific set of URLs, or to write logging data to a
  +relational database.
  +
  +  file:My/Notify.pm
  +  ------------------------
  +  package My::Notify;
  +  use strict;
  +  use Apache::Constants(':common');
  +
  +  use Mail::Send;
  +
  +  sub handler {
  +      my $r = shift;
  +
  +      my $email = $r->server->server_admin || return DECLINED;
  +
  +      my $mail = Mail::Send->new(
  +          To      => $email,
  +          Subject => "mod_perl Notification",
  +      );
  +      my $file = $r->filename;
  +      my $fh = $mail->open;
  +      $fh->print("File '$file' was accessed");
  +      $fh->close;
  +
  +      return DECLINED; # let apache write to the lot
  +  }
  +  1; # modules must return true
  +
  +The I<httpd.conf> setup:
  +
  +  <location /private>
  +      SetHandler perl-script
  +      PerlLogHandler My::Notify
  +  </location>
   
   =for html
   <a class="more" href="../index.html#logging">&#171&nbsp;back</a>
  
  
  
  1.2       +35 -30    modperl-docs/src/start/tips/registry.pod
  
  Index: registry.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/start/tips/registry.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- registry.pod      25 Apr 2002 07:01:02 -0000      1.1
  +++ registry.pod      26 Apr 2002 01:43:11 -0000      1.2
  @@ -5,38 +5,43 @@
   
   =head1 Running CGI scripts with mod_perl
   
  -Existing CGI scripts will run much faster under mod_perl.
  -And converting existing CGI scripts to run under mod_perl is easy.
  +Existing CGI scripts will run much faster under mod_perl.  And
  +converting existing CGI scripts to run under mod_perl is easy.
   
  -For example, here's an existing CGI script called F<hello.cgi>.
  +For example, here's an existing CGI script called I<hello.cgi>.
   
  -    #!/usr/local/bin/perl -w
  -    use strict;
  -    use CGI;
  -    my $q = CGI->new;
  -    print $q->header,
  -          $q->start_html,
  -          $q->h1('Hello World!'),
  -          $q->end_html;
  -
  -This script can now be run as-is under Apache::Registry by using the
  -following configuration in httpd.conf:
  -
  -    <files hello.cgi>
  -        SetHandler perl-script
  -        PerlHandler Apache::Registry
  -        Options ExecCGI
  -    </files>
  -
  -That's basically it.  Your scripts do need to be well coded, but there's 
even the
  -Apache::PerlRun module to help with those "less clean" programs.
  -
  -So how much faster do scripts run under Apache::Registry?  Obviously, it 
depends
  -on the script, but the "hello.cgi" script above ran 
  -at 7.3 requests per second as a CGI script and 243.0 requests per second 
with Apache::Registry.
  -
  -=for html
  -<small>Tested with Apache Benchmark (ab -n 1000) on Linux PIII-550Mhz, 
Apache version 1.3.20</small>
  +  file:hello.cgi
  +  --------------
  +  #!/usr/local/bin/perl -w
  +  use strict;
  +  use CGI;
  +  my $q = CGI->new;
  +  print $q->header,
  +        $q->start_html,
  +        $q->h1('Hello World!'),
  +        $q->end_html;
  +
  +This script can now be run as-is under C<Apache::Registry> by using the
  +following configuration in I<httpd.conf>:
  +
  +  <files hello.cgi>
  +      SetHandler perl-script
  +      PerlHandler Apache::Registry
  +      Options ExecCGI
  +  </files>
  +
  +That's basically it.  Your scripts do need to be well coded, but
  +there's even the C<Apache::PerlRun> module to help with those "less
  +clean" programs.
  +
  +So how much faster do scripts run under C<Apache::Registry>?
  +Obviously, it depends on the script, but the I<hello.cgi> script above
  +ran at 7.3 requests per second as a CGI script and 243.0 requests per
  +second with C<Apache::Registry>.
  +
  +=for html 
  +<small>Tested with Apache Benchmark (ab -n 1000) on Linux PIII-550Mhz,
  +Apache version 1.3.20</small>
   
   For more information on running CGI scripts under mod_perl please see
   L<mod_perl FAQs|"../../docs/1.0/faqs/index.html">.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to