Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

modperl PerlAuthenHandler script persistence

by SirBones (Friar)
on Mar 28, 2006 at 19:55 UTC ( #539795=perlquestion: print w/replies, xml ) Need Help??
SirBones has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks; I beg your pardon for this, because it seems I should be able to find the answer somewhere, and it may not be a pure Perl question. But after 2 days of google searches and banging my head on my desk all I have is a dented desk (and a headache.) I'm the first to admit I don't really understand Apache/modperl/data persistence very well, so bear with this fool for a bit...

I have a user authentication script (PerlAuthenHandler) which stores a time value for each authenticated user in a hash. Every time the script runs it updates the value, checks it, etc. Basically if a user has authenticated recently I don't force another check (the underlying authentication is via LDAP.) I want this hash to be persistent across calls to the handler (of course.)

Under Apache 1.3 with an early modperl version this works fine. But now I'm bringing up a new server with Apache 2 and modperl 2, I've set up the httpd.conf and perl.conf file directives the same way, and I can't get it to work. Under Apache 2 the script appears to not be persistent; the hash gets reinitialized with every authentication call.

It's been a while since I set up my old 1.3 server, but I don't recall doing anything special other than installing modperl and setting up the appropriate apache directives. I certainly had to make a lot of changes to my authentication script to get it running under Apache/modperl 2, and it works fine except for this lack of persistence. Is there some configuration value controlling this behavior whose default has changed between Apache or modperl versions?

Here are the relevant entries in my Apache configuration files; they are unremarkable. I include them for completeness. They are identical (except for the name of the modperl module) on both servers.

LoadModule perl_module modules/ . . . <Directory /> Options FollowSymLinks AllowOverride all PerlAuthenHandler MyApache::MyAuthScript AuthType Basic AuthName "Welcome to My Server" Require valid-user </Directory> . . . # ModPerl setup Alias /perl/ /data/www/perl/ <Location /perl/> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI Order allow,deny Allow from all </Location>

Thanks, in advance, muchly. I know this spills over to non-Perl issues as well, but hopefully I'm not too off topic.

"This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt

Replies are listed 'Best First'.
Re: modperl PerlAuthenHandler script persistence
by philcrow (Priest) on Mar 28, 2006 at 21:38 UTC
    Seeing that no one more knowledgeable has responded I'll throw in a suggestion from the side. Perhaps you could tie the hash? Or would that be too persistent?


      Hm. Tied variables. YAPTIAD (Yet Another Perl Thing I Ain't Done. :-) ). If there isn't a simple answer as to why I'm seeing two different behaviors, I'll have a look and see if that might work; thanks.

      "This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt
Re: modperl PerlAuthenHandler script persistence
by perrin (Chancellor) on Mar 29, 2006 at 00:19 UTC
    In both apache 1 and apache 2, each request may be handled by a different process, so you can't just keep things in a hash in memory if you want them to be global. The exception to this is if you were using apache 1 on Windows. There it only used one thread before and now uses multiple. Were you running it on Windows?

      No, sorry, I forgot to mention the OS. It's Linux in both cases. The mystery deepens. Do you think the aberrant behavior is actually with my older server, and the new one is WAD?

      "This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt
        Limiting the number of children to 1 would explain old behaviour
Re: modperl PerlAuthenHandler script persistence
by Arunbear (Prior) on Mar 29, 2006 at 13:19 UTC
    here's an alternative strategy to consider (for the auth handler):
    use Cache::FileCache; my $cache = Cache::FileCache->new; if(not $cache->get( $username )) { do_authentication(); if($authentication_succeeded) { $cache->set( $username, 1, "10 minutes" ); } }
    advantages of Cache::Cache:
      Cache::Cache is slow, and Cache::SharedMemoryCache is especially slow. I'd suggest using Cache::FastMmap instead if you're concerned about performance.

      That looks great. Cache::Cache seems to be what I should have been using all along, rather than my original kludge. I'll try it today; thanks so much.


      "This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://539795]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2018-06-18 08:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.