Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > mod_perl and global variables during startup

Reply
Thread Tools

mod_perl and global variables during startup

 
 
nicc777
Guest
Posts: n/a
 
      07-12-2005
Hi,

I am not exactly new to Perl, but very new to mod_perl.

In short, here is what I want to achieve:

1. Have two global hashes loaded during startup (maybe in startup.pl
??). The values are obtained from a DB

2. From time to time send a special HTTP request to the server to
refresh the hashes from a DB source

In theory, this should prevent me from going to the DB for info that
changes rarely, and when they do change I could have a mechanism (my
idea is around a special HTTP request) to reload the hashes if the data
do change.

Any ideas? Code samples will be most welcome.

Thanks

 
Reply With Quote
 
 
 
 
Keith Keller
Guest
Posts: n/a
 
      07-12-2005
On 2005-07-12, nicc777 <(E-Mail Removed)> wrote:
>
> In short, here is what I want to achieve:
>
> 1. Have two global hashes loaded during startup (maybe in startup.pl
> ??). The values are obtained from a DB
>
> 2. From time to time send a special HTTP request to the server to
> refresh the hashes from a DB source


You could run into problems with 2. On some (all?) systems, each http
process has its own variable space, and you have no way of specifying
with an HTTP request which httpd process you get. So, if you send five
requests, for example, and the server has 10 httpd's running, you might
hit half of the httpd's and reload their variables, or you might hit the
same httpd 5 times.

> In theory, this should prevent me from going to the DB for info that
> changes rarely, and when they do change I could have a mechanism (my
> idea is around a special HTTP request) to reload the hashes if the data
> do change.


What is the reason you don't want to hit the db? In any case, you might
use a file instead, and touch the file (or update its contents with the
new data, even); then, a CGI can look at the file to see if it needs to
hit the database (or even look at the file to get the necessary
changes).

In general, trying to tell a mod_perl httpd to change something is
nontrivial, and you should try to put such logic in your script (or
mod_perl library) instead, and do as little as possible in startup.pl.

Finally, you might ask for strategies on the mod_perl mailing list; many
more mod_perl experts frequent there than here (and all much more expert
than I). Look at perl.apache.org for mailing list info.

--keith

--
http://www.velocityreviews.com/forums/(E-Mail Removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information

 
Reply With Quote
 
 
 
 
Richard Gration
Guest
Posts: n/a
 
      07-13-2005
On Tue, 12 Jul 2005 12:14:16 -0700, Keith Keller wrote:

> On 2005-07-12, nicc777 <(E-Mail Removed)> wrote:
>>
>> In short, here is what I want to achieve:
>>
>> 1. Have two global hashes loaded during startup (maybe in startup.pl
>> ??). The values are obtained from a DB
>>
>> 2. From time to time send a special HTTP request to the server to
>> refresh the hashes from a DB source

>
> You could run into problems with 2. On some (all?) systems, each http
> process has its own variable space, and you have no way of specifying
> with an HTTP request which httpd process you get. So, if you send five
> requests, for example, and the server has 10 httpd's running, you might
> hit half of the httpd's and reload their variables, or you might hit the
> same httpd 5 times.
>
>> In theory, this should prevent me from going to the DB for info that
>> changes rarely, and when they do change I could have a mechanism (my
>> idea is around a special HTTP request) to reload the hashes if the data
>> do change.


I have exactly the same global hash situation as you, except I have only
one, not 2 It is initialised from the database at server startup time.
The Unix epoch time at which this happens is stored in the hash, under the
key reconfig. I also have a field called reconfig on the cfg_main database
table.

For every request, I check to see if the reconfig time in the db is more
recent than the one stored in the config hash. If I need to reread the
config, I do, which updates the reconfig value in the hash too.

This totally gets round the multiple children issue, they all re-read as
necessary. This system has worked well for me for years.

Rich
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
mod_perl installed, but mod_perl.so file not created bennett@peacefire.org Perl Misc 2 01-25-2006 10:53 PM
Global variables in mod_perl Gunnar Hjalmarsson Perl Misc 6 05-18-2004 09:56 AM
mod_perl errors: prototype mismatch ... during global destruction ian douglas Perl 0 08-18-2003 11:17 PM



Advertisments