You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Greg Cope <gj...@rubberplant.freeserve.co.uk> on 2000/08/13 23:00:07 UTC

my transhandler runs only once in each child ?!?

Dear All

I've a bug somewhere that I cannot appear to spot..

I have writen parts of a transhandler to handle session's.  It works in
once in each child and then does not appear to be executed again.

I've looked through The Guide and could not see anything there, nor in
the 'Apache modules in Perl and C'.  I must be missing somehing (a clue
for a start ;-).

The obvious answer is that a variable is not being redefined /
initialised.

Any ideas appreciated.

Greg Cope

### some clues below (I hope)

I have these lines in my startup.pl:

use tinasm::Session();

$tinasm::Session::DEBUG = 1;
$tinasm::Session::DIR_MATCH = 'test';
$tinasm::Session::REDIRECT = 1;
$tinasm::Session::USE_ENV = 1;

##### end of startup.pl, snippet #####

part of the module below

##### code snippet #####
package tinasm::Session;

use strict;
use Apache;
use Apache::Constants qw(DECLINED REDIRECT OK);
use Digest::MD5 qw(md5_hex);

use constant SESSION_ID_LENGTH => 8;

use vars qw($DIR_MATCH $COOKIES_ONLY $ARGS_ONLY 
        $DEBUG $REDIRECT $URI_FIRST $USE_ENV);

Apache->push_handlers("PerlTransHandler", \&transhandler);

sub transhandler {

        my $r = shift;
        unless ($r->uri =~ m!$DIR_MATCH!o) {
                print STDERR "SESSION-MANAGER-$$-URI not matched\n"
                        if $DEBUG;
                return DECLINED;
        }

        print STDERR "SESSION-MANAGER-$$-URI match\n" if $DEBUG;

..... handler goes on for another 200 lines so I've snipped it - if
anyone wants to look at it drop me a line.


Re: my transhandler runs only once in each child ?!?

Posted by Greg Cope <gj...@rubberplant.freeserve.co.uk>.
Eric Cholet wrote:
> 
<snippage>
> >
> > Apache->push_handlers("PerlTransHandler", \&transhandler);
> 
> this will trigger the handler for the first request. Nothing
> will trigger it for subsequent requests. If you want it to run
> for every request, why not just drop the push_handlers call
> and add PerlTransHandler tinasm::Session to httpd.conf.

Thanks Eric,

IIRC I had tried that arround a month ago -  and it did not work - but
the bug was elsewhere.  The reason I was doing it this way was so that I
could just do a :

use tinasm::Session;

in a statup file - which I think is {now think was} more elegant that
adding a transhandler, that'll teach me!

Now all working thanks

Greg

> 
> >
> > sub transhandler {
> >
> >         my $r = shift;
> >         unless ($r->uri =~ m!$DIR_MATCH!o) {
> >                 print STDERR "SESSION-MANAGER-$$-URI not matched\n"
> >                         if $DEBUG;
> >                 return DECLINED;
> >         }
> >
> >         print STDERR "SESSION-MANAGER-$$-URI match\n" if $DEBUG;
> >
> > ..... handler goes on for another 200 lines so I've snipped it - if
> > anyone wants to look at it drop me a line.
> 
> --
> Eric



Re: my transhandler runs only once in each child ?!?

Posted by Eric Cholet <ch...@logilune.com>.
> Dear All
> 
> I've a bug somewhere that I cannot appear to spot..
> 
> I have writen parts of a transhandler to handle session's.  It works in
> once in each child and then does not appear to be executed again.
> 
> I've looked through The Guide and could not see anything there, nor in
> the 'Apache modules in Perl and C'.  I must be missing somehing (a clue
> for a start ;-).
> 
> The obvious answer is that a variable is not being redefined /
> initialised.
> 
> Any ideas appreciated.
> 
> Greg Cope
> 
> ### some clues below (I hope)
> 
> I have these lines in my startup.pl:
> 
> use tinasm::Session();
> 
> $tinasm::Session::DEBUG = 1;
> $tinasm::Session::DIR_MATCH = 'test';
> $tinasm::Session::REDIRECT = 1;
> $tinasm::Session::USE_ENV = 1;
> 
> ##### end of startup.pl, snippet #####
> 
> part of the module below
> 
> ##### code snippet #####
> package tinasm::Session;
> 
> use strict;
> use Apache;
> use Apache::Constants qw(DECLINED REDIRECT OK);
> use Digest::MD5 qw(md5_hex);
> 
> use constant SESSION_ID_LENGTH => 8;
> 
> use vars qw($DIR_MATCH $COOKIES_ONLY $ARGS_ONLY 
>         $DEBUG $REDIRECT $URI_FIRST $USE_ENV);
> 
> Apache->push_handlers("PerlTransHandler", \&transhandler);

this will trigger the handler for the first request. Nothing
will trigger it for subsequent requests. If you want it to run
for every request, why not just drop the push_handlers call
and add PerlTransHandler tinasm::Session to httpd.conf.

> 
> sub transhandler {
> 
>         my $r = shift;
>         unless ($r->uri =~ m!$DIR_MATCH!o) {
>                 print STDERR "SESSION-MANAGER-$$-URI not matched\n"
>                         if $DEBUG;
>                 return DECLINED;
>         }
> 
>         print STDERR "SESSION-MANAGER-$$-URI match\n" if $DEBUG;
> 
> ..... handler goes on for another 200 lines so I've snipped it - if
> anyone wants to look at it drop me a line.
 
--
Eric



Re: my transhandler runs only once in each child ?!?

Posted by Greg Cope <gj...@rubberplant.freeserve.co.uk>.
Matt Sergeant wrote:
> 
> On Sun, 13 Aug 2000, Greg Cope wrote:
> 
> > Apache->push_handlers("PerlTransHandler", \&transhandler);
> 
> push_handlers is temporary, not permanent. And this line only gets
> executed once.

Thanks Mat - Explains everything.  I though it might be something as
simple as this, I'll birch myself later.

I spent hours yesterday looking at this. Doh,  Doh,  Doh !!!

Thanks again

Greg

ps You're up early


> 
> --
> <Matt/>
> 
> Fastnet Software Ltd. High Performance Web Specialists
> Providing mod_perl, XML, Sybase and Oracle solutions
> Email for training and consultancy availability.
> http://sergeant.org | AxKit: http://axkit.org


Re: my transhandler runs only once in each child ?!?

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 14 Aug 2000, Matt Sergeant wrote:

> On Sun, 13 Aug 2000, Greg Cope wrote:
> 
> > Apache->push_handlers("PerlTransHandler", \&transhandler);
> 
> push_handlers is temporary, not permanent. And this line only gets
> executed once.

of course, if you wanted something like that, your module (if loaded at 
startup) can do this:

{
    package Apache::ReadConfig;
    push @PerlTransHandler, join '::', __PACKAGE__, 'transhandler';
}


Re: my transhandler runs only once in each child ?!?

Posted by Matt Sergeant <ma...@sergeant.org>.
On Sun, 13 Aug 2000, Greg Cope wrote:

> Apache->push_handlers("PerlTransHandler", \&transhandler);

push_handlers is temporary, not permanent. And this line only gets
executed once.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org