|XP is just a number|
Re: Storing data with mod_perl (are those handlers different) ?by lachoy (Parson)
|on Apr 08, 2001 at 20:53 UTC||Need Help??|
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.