Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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...)
I run a script using Perl and FastCGI (main.fcgi) . This script includes another scipt that holds settings (variables)for the main script (

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

If main.fcgi hadn't been a fcgi-script, the altered settings in 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 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(""); }
, but it (also) has to be included before this, since it holds settings that is to be used before this code piece is executed.

Replies are listed 'Best First'.
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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://826652]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-09-21 21:28 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (253 votes). Check out past polls.