Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Passing Arguments to Perl Modules during Apache Startup

by andreychek (Parson)
on Sep 12, 2001 at 23:40 UTC ( [id://111992]=perlquestion: print w/replies, xml ) Need Help??

andreychek has asked for the wisdom of the Perl Monks concerning the following question:

Howdy,

I have some modules which make use of Apache and mod_perl. I have two things I would like to do with them:

1. Have the modules preloaded at Apache startup time
2. Pass configuration information to them as they are loaded

It's easy enough to preload them. I can either use the Apache "PerlModule" directive (preferred), or include a startup.pl file. The problem I am having is passing the configuration information to them.

Now, I've looked into using PerlSetVar, PerlSetEnv and PerlPassEnv. The problem is, these directives only seem to work when called through Apache via a browser. But when Apache is initially loading, Apache does not seem to pass any of this information to modules as it is loading them.

The data I need to pass are just a strings -- I don't necessarily need to pass arrays or hashes.

Just to add some spice to the this problem, I definitely would like to keep the solution to this within the httpd.conf file. The reason for this is that I would like to package these modules for easy use on multiple systems. I don't want sysadmins to have to dig all across their systems to find the configuration data for these modules. This configuration data I'm referring to is all webserver related, and fits in well with the httpd.conf file. We'll make some sysadmin happy by keeping this config info with the rest of the web config data in the httpd.conf. However, if the only solution you can think of wouldn't go into the httpd.conf file, I would still be glad to hear your thoughts :-)

Does anyone have any suggestions on how one might go about passing an argument to a Perl module during Apache's startup process? I would love to hear from you! Thanks :-)

-Eric
  • Comment on Passing Arguments to Perl Modules during Apache Startup

Replies are listed 'Best First'.
Re: Passing Arguments to Perl Modules during Apache Startup
by ncw (Friar) on Sep 12, 2001 at 23:51 UTC
    Buy the mod_perl book - it explains in depth how to make mod_perl provide extensions to httpd.conf syntax which sounds exactly what you want!

    The book's home is here

    http://www.modperl.com/

    And it is called Writing Apache Modules with Perl and C

    PS Thoughtfully the author has put the relevant chapter online <a href=http://www.modperl.com/book/chapters/ch8.html">here ;-)

Re: Passing Arguments to Perl Modules during Apache Startup
by echo (Pilgrim) on Sep 13, 2001 at 11:47 UTC

    Now, I've looked into using PerlSetVar, PerlSetEnv and PerlPassEnv. The problem is, these directives only seem to work when called through Apache via a browser. But when Apache is initially loading, Apache does not seem to pass any of this information to modules as it is loading them.

    Use PerlSetVar the usual way:

    PerlSetVar foo bar

    Then in your startup.pl file, access them like this:

    my $config = Apache->server->dir_config('foo');

    On a side note, it's best if possible to stay away from PerlSetEnv/PerlPassEnv, because setting up the environment at request time is costly. If you don't use the %ENV at all in your modules then you can save some cycles by configuring PerlSetupEnv Off.

    Just to add some spice to the this problem, I definitely would like to keep the solution to this within the httpd.conf file.

    Check out Perl Sections: you can directly set yourp ackage variables from httpd.conf:

    <Perl> $My::Config::foo = 'bar'; </Perl>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://111992]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found