Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Storing data with mod_perl (are those handlers different) ?

by lachoy (Parson)
on Apr 08, 2001 at 20:53 UTC ( #70853=note: print w/replies, xml ) Need Help??


in reply to Storing data with mod_perl (are those handlers different) ?

If it's a relatively simple configuration file/info, you can just store the data structure in a package variable. It won't be shared among all the Apache children (each will generally have its own copy) but if you're not making changes to the file that's not a big deal. And I think depending on how your OS implements shared memory the memory might be shared among the children until you make a change. (Check out the mod_perl Guide for lots of info on shared memory.

One for something like this is to read in the file and set the config info in a ChildInit handler. To do this, define your routine from above in your startup.pl startup file and then add the routine into the ChildInit handler stack. That way you'll always know it's there.

The downside of this is that you can't do dir_config calls within your startup.pl file because you're not in a directory when Apache is starting up. You can, however, read server configuration variables and work from there. For instance, if you have five different configuration files you could map a configuration name to a file location, read them in at startup and store them in a My::App::Config package, then call the specific configuration from other handlers depending on the configuration name set in a PerlSetVar location directive.

For something like this you might also look into the Singleton pattern (implemented by Class::Singleton) so you can refer to the configuration from any other handler with a simple call like My::App::Config->instance.

As for your second question, the two would be in the same memory/name space. If you want you can separate them by setting an additional PerlSetVar in the two different location directives that specifies which configuration (or whatever) you're using.

Hope this helps.

Chris
M-x auto-bs-mode

Replies are listed 'Best First'.
Re: Re: Storing data with mod_perl (are those handlers different) ?
by araqnid (Beadle) on Apr 08, 2001 at 22:18 UTC
    Actually, if you read the config file during the execution of a "PerlRequire" or "PerlModule" (or <Perl> ?) directive, then it will be stored in the parent process and hence *will* be shared amongst the child processes.

    That's also your chance to do any setting up that you need to do as root, e.g. creating new directories and "chown"ing them.

    So you could have a read_config.pl in /etc/apache (or wherever) that simply reads the config data and drops it into your handler's package. Then just PerlRequire read_config.pl and there you go!

    The disadvantage with doing this, of course, is that the configuration file is not reread simply by doing apachectl graceful. Which may not be what you want.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://70853]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2018-08-20 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (188 votes). Check out past polls.

    Notices?