in reply to mod_perl how to process static content

Usually I just target specific URLs with mod_perl, by using Location blocks. However, if you really want to handle everything except some specific directories with mod_perl, you can use default-handler:
SetHandler default-handler
That tells apache to use the normal HTTP handler.

Replies are listed 'Best First'.
Re^2: mod_perl how to process static content
by atento (Novice) on Mar 24, 2008 at 18:40 UTC
    Yeah, I know it but forget.

    Thanks!

    So now I will try to write PerlTransHandler which fired before PerlContentHandler and this code will set up default handler for location matches... hope it helps.
Re^2: mod_perl how to process static content
by atento (Novice) on Mar 24, 2008 at 20:20 UTC
    Fuck, there are configuration directive and I have no ideas how to manipulate this from runtime.

    Meditating the Apache2::Const module got no results how to revert the default-handler :(
    Seems that apache "Handlers" are used to replace only "default-handler"s


    I've tried to set PerlResponseHandler at runtime in PerlTransHandler which rises before one.

    Apache config:
    <VirtualHost> SetHandler perl-script PerlTransHandler My::Apache::Rewrite </VirtualHost>

    My/Apache/Rewrite.pm
    -------------------------
    package My::Apache::Rewrite; use strict; use warnings; use Apache2::RequestRec (); use Apache2::Const -compile => qw(FORBIDDEN DECLINED OK DONE); sub handler { my $r = shift; unless(($r->uri ne '/' && !$r->args) && (-d $r->filename || -f $r- +>filename)) { $r->set_handlers(PerlResponseHandler => 'My::Apache::Main'); } return Apache2::Const::OK; } 1;
    No results because main handler is always set :(
      I don't see any good reason to do this anywhere but your conf file. However, if you really want to do it, look at the example here.
      GUYS! I FOUNDED THE SHORTEST WAY!

      Here addition to my original post:

      Add just only one line to handler's code begin in file:
      My/Apache/Main.pm ----------------
      sub handler { my $r = shift; return Apache2::Const::DECLINED if (-d $r->filename || -f $r->filename); ...
      Since now I'll smoke mod_perl api guide till it ends...
        Nifty, but you still start a mod_perl process and to make matters worse you make two separate filechecks (which are slow by itself) for each and every hit to your pages. At least you should use the special _filehandle for the second check to save yourself a system call.

        In Practical mod_perl we find the following (when speaking about a set-up with one mod_perl server):

        While you will be happy to have these monster processes serving your scripts with monster speed, you should be very worried about having them serve static objects such as images and HTML files. Each static request served by a mod_perl-enabled server means another large process running, competing for system resources such as memory and CPU cycles. The real overhead depends on the static object request rate. Remember that if your mod_perl code produces HTML code that includes images, each of these will produce another static object request.
        If you cannot have separate servers for static and dynamic content, at least let the static content be served by a non mod_perl handler (i.e. Apache's default handler).

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James