Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

What config info belongs where for web apps?

by cbrandtbuffalo (Deacon)
on Dec 13, 2005 at 19:46 UTC ( #516398=perlquestion: print w/replies, xml ) Need Help??

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

We have a fairly standard web development set-up with dev, QA, and prod environments. To smoothly deal with migration through these environments, we've developed a configuration module that has various smarts in it to return the correct data depending on where you are. In dev, file locations, paths, URLs, database info, etc. are based on your individual sandbox settings. In QA, all of these things point to the right places on our QA boxes; likewise with prod.

This all works quite well for us for most config info. However, we've run into a strange situation with mod_perl. If you load config data just once per process, it works fine for pseudo-static information like machine environment and path info. But information that changes per-hit such as the current user (REMOTE_USER) needs to be loaded each time.

From a design perspective, where should that information live and how should it be loaded? Should we 'new' our config module on each hit and include per-hit data there (and re-run all the code), or should a config module contain only data that doesn't change once the process if fired up? Or should we have two modules?

Thanks for any insight.

Update: Did some research based on badaiaqrandista's response and found some information on scope in web apps that gives more detail.

  • Comment on What config info belongs where for web apps?

Replies are listed 'Best First'.
Re: What config info belongs where for web apps?
by badaiaqrandista (Pilgrim) on Dec 14, 2005 at 00:50 UTC

    In web applications, there are four basic conceptual scopes:

    • request scope
    • session scope
    • application scope
    • machine scope

    Configuration files are only suitable to hold values for variables in 'machine' and 'application' scope

      Thanks for the info. I added a link with some additional detail in the main body above.
        The link describes a slightly different kind of scoping, instead of having 'machine scope', which is larger than 'application scope', the link explains about 'page scope', which is smaller than the 'request scope'. Those scopes come from my own humble experience. The most important point is that you understand the differences between each scope and what each should handle.
Re: What config info belongs where for web apps?
by duckyd (Hermit) on Dec 13, 2005 at 23:12 UTC
    Generally, I think information that changes per-hit doesn't really fit the definition of "config data". I would keep a config module limited to information that is static, and access/organize per-hit data seperately.
Re: What config info belongs where for web apps?
by jhourcle (Prior) on Dec 14, 2005 at 00:31 UTC

    I'm with duckyd on this one. The types of things I keep in config files are:

    • Path to useful files that Perl might need to load.
    • base URL to the CSS / images / javascript and other files I might need to refer to in the HTML
    • Info on how to generate a URL on the machine (not all of my stuff stays in a 'cgi-bin' directory, and I might need port info, and the name of the server)

    Basically, it's all machine-specific info. Stuff like REMOTE_ADDR and the like get loaded from %ENV on a per-hit basis. You can use modules for it, but you want to call an instance of the module once per hit -- you don't want the stuff stored as globals in the module, or you're just asking for trouble. (if you have a long-running process, process B may kick off before process A finishes ... you use globals, and you don't know what A might get when it asks the module for info)

    PS -- CGI can return environmental variables used in CGI processing.

Re: What config info belongs where for web apps?
by Mandrake (Chaplain) on Dec 14, 2005 at 03:19 UTC
    Configuration modules can handle info specific to application scope pretty well. But session specific information should be handled using environment variables or with some session handling modules.

    Better to use a session handling module like Apache:Session.
Re: What config info belongs where for web apps?
by kulls (Hermit) on Dec 14, 2005 at 03:28 UTC
    All hardcoded values relevent to your wepapp and it's common across the webapp, then it should come under config file.
    -kulls

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-11-16 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?