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

FastCGI - updating settings

by DreamT (Pilgrim)
on Mar 04, 2010 at 08:29 UTC ( #826652=perlquestion: print w/ replies, xml ) Need Help??
DreamT has asked for the wisdom of the Perl Monks concerning the following question:

(I couldn't come up with a better thread title...)
Hi,
I run a script using Perl and FastCGI (main.fcgi) . This script includes another scipt that holds settings (variables)for the main script (settings.pl).

There also is a third script, an administration program that alters settings in settings.pl.

If main.fcgi hadn't been a fcgi-script, the altered settings in settings.pl had been used immediately. But, as it is now I have to restart Apache for the changes to take effect.

Is there a way to get around this? I.e. can i include settings.pl in main.fcgi in a way that makes the changes take effect immediately?

I know that I can inlude in the
while ($query = new CGI::Fast) { require("settings.pl"); }
, but it (also) has to be included before this, since it holds settings that is to be used before this code piece is executed.

Comment on FastCGI - updating settings
Download Code
Re: FastCGI - updating settings
by almut (Canon) on Mar 04, 2010 at 08:49 UTC

    Maybe do is what you're looking for. In contrast to require, it does not keep track of what's already been loaded. In any case, as the process is running persistently, you'll have to have some mechanism that triggers the reloading of the settings. Several ways are conceivable:

    • Check the modification date of settings.pl at every request that's being made, and reload it if its modification date has changed.
    • Have a special URL that's associated with a routine that does the reloading (make sure the request is authenticated).
    • Send the process (or process group) a signal (e.g. USR1 via kill), and have the signal handler trigger the reloading.
    • ...

    P.S. As you have things now, you may not actually have to restart Apache; killing the FGCI processes directly is usually sufficient, because mod_fastcgi (with a typical configuration) will simply respawn new processes if the old ones have vanished...

Re: FastCGI - updating settings
by goeb (Pilgrim) on Mar 04, 2010 at 08:54 UTC
    The following should do the trick, it will exit if the mtime of $file (edit: relative to the script's start time, of course...) is less than zero, ie. $file has been modified after the script's start time:
    while (my $cgi = new CGI::Fast ()) { # process the current request... exit if -M $file < 0; }
    Then let the webserver take care of restarting it. (Note that the exit call is placed after the processing of a request, since the while loop is only entered after a new request is made to the script, immediate exit could break the connection. This leaves one request being processed with the old settings.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-07-26 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls