locked_user rumos-er has asked for the wisdom of the Perl Monks concerning the following question:

Hi, ALL.


I have few questions about mod_perl, so I assume I newbie in this questions and will be very grateful for help.
1. http://www.mid.main.vsu.ru/docs/iAS/web.902/q20203/control.html#Restarting_Techniques -I've noticed here that httpd_perl had to be started. But I don't see it - does it mean that ModPerl started incorrectly ?

2. I try to use Apache::Reload but I get trouble - it gets mod_perl.pm in it's $INCS hash placed in /dev/null and then gets error in require. First question is why does it get mod_perl in modules list. Now I've set Apache2::Reload as a handler, but in manual everyting is written about Apache::Reload.

3. How does $ENV work ? (will be grateful for url :) - Can I use it like in normal CGI application ?

4. How will it work:

kernel.pl #!/usr/bin/perl ... use kernel my $kernel=new kernel; ... $self->print_header(); print $self->{pageResult}; ---------- kernel.pm package kernel; .. use CGI; use ModPerl::Registry; use ModPerl::Util; sub new { my $self={}; shift; bless($self); $self->init(); return $self; }; sub init { ... $self->{libs}->{cgi}=new CGI; ... }; sub accept_query { my $self=shift; ... #I take and proceed all CGI params from $self->{libs}->{cgi} and then +cache them in $self->{accepted_query}(hash reference). I use this met +hod for not calling CGI->param('bla') every time I need params. };

So the question is: do I need additional middle key in $self->{accepted_query} which includes $ENV{DOCUMENT_URI} and some other params for guarantee of it's unique per one HTTP request (or I won't have any troubles with global vars here 'cause $self(kernel.pm)==$kernel(!!kernel.pl) is a global var?)

5. in my CMS I use all my modules by method 'load of package kernel'. In CGI version it caches using modules' new or init method calls, if in page context I require them more then once. In mod_perl version I added some part of code from Apache::Reload

#load package sub load { my $self=shift; my $lib=shift; my $where_self=shift; my $need_reload=0; $self->{Reload}->{$lib}->{file}=$self->{config}->{root_cgi_fol +der}.$self->_package_to_module($lib); open(F, ">>".$self->{config}->{root_cgi_folder}."reload.log"); if ( $self->{Reload}->{$lib}->{utime} ) { if ( time()-$self->{Reload}->{$lib}->{utime} > 60 ) {# +we'll do reload every 60 seconds if it needed for not calling file st +at on every call my $mtime = (stat $self->{Reload}->{$lib}->{fi +le})[9]; if ($mtime != $self->{Reload}->{$lib}->{utime} + ) { $self->{Reload}->{$lib}->{utime}=$mtim +e; $need_reload=1; ModPerl::Util::unload_package($lib); print F $$." ".$self->date_format('%0 +day.%0month.%year %0hour:%0min:%0sec', $mtime)." ".$lib." - RE +LOAD !!!!!!!!!!!!!!!!!!!!!!!!\n"; } else { print F $$." ".$self->date_format('%0 +day.%0month.%year %0hour:%0min:%0sec', time())." ".$lib." - SK +IPED!!!\n"; }; }; } else { $need_reload=1; my $mtime=(stat $self->{Reload}->{$lib}->{file})[9]; print F $$." ".$self->date_format('%0day.%0month.%yea +r %0hour:%0min:%0sec', $mtime)." ".$lib." - First load\n"; $self->{Reload}->{$lib}->{utime}=$mtime; }; close(F); return 0 if $self->{loaded_libs}->{$lib} && !$need_reload; my $libobj; eval ' use '.$lib.'; $self->{libs}->{\''.$lib.'\'}=new '.$lib.'('.($where_s +elf ? '$self->{admin}':'$self').') if $need_reload; '; if ($@) { my $error=$@; undef($@); return $error; } else { $self->{loaded_libs}->{$lib}=1; return 0; #return $self->{libs}->{$lib}; }; };

-so why do I see at the same pids "first load".. ?

6. method exit(). I know that it is impossible to use it. But I use it in 2 methods ($kernel->error_admin, $kernel->error_client) - I need them for checking userinput and if something is wrong - to give error page to user and stop calling method, package, process(In CGI version). It's written here that I can override CORE::exit and use Apache::exit
http://www.mid.main.vsu.ru/docs/iAS/web.902/q20203/porting.html#Terminating_requests_and_process
-I've used this example, but now I get this message in error_log:
ModPerl::Util::exit: (120000) exit was called at /usr/local/lib/perl5/site_perl/5.8.8/mach/Apache2/compat.pm line 363
I haven't read compat.pm, but as I know it's responsible for compatibility of scripts written under mod_perl1 with mod_perl2 enviroment.
6.1. Sometimes I also see this - notice child pid 53772 exit signal Segmentation fault (11) - so the question is - does it happen because standart exit is used and it interrupts mod_perl-process incorrectly, and dying mod_perl-process does not give any signal about its death to the controll process ?

Thnx for your time and attention.
Best regards,
Rumos.

Replies are listed 'Best First'.
Re: few questions about ModPerl2
by perrin (Chancellor) on Nov 29, 2006 at 13:48 UTC
    If you really are using mod_perl 2, you should read the mod_perl 2 documentation. The links you gave are all for outdated copies of the mod_perl 1 docs. The correct ones are here.
Re: few questions about ModPerl2
by themage (Friar) on Nov 29, 2006 at 10:45 UTC
    Hi,

    I have still another question about ModPerl2.

    Why don't modperl2 allow directory redirection to some indexfile, nor does it allow mod_dir to handle it by DirectoryIndex directive?

    In my prespective/basic knowledge, if a module don't know how to handle a request it should return a message to apache that the request wasn't handled, and not a error status. Unless, obviously, that the module is the last module that can handle the request. ModPerl2 isn't doing this. It don't allow anyother module to handler anything after him.

    Is there any way to correct this?

      Apache maps requests to specific handlers based on what's in your httpd.conf file. Usually you can configure it to not send directory requests to mod_perl. You may find this thread helpful.