Where to store application config?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Where to store application config?

Post by pickle »

Hi everyone,

I've got a web application server that runs 30 or so separate web applications. All their database credentials and access levels are stored in a central config file. Each separate application loads that file & picks out it's particular database information and access levels.

My question is - do you think it makes more sense to have a central file, or to have each application have it's own config file that stores the database credentials and access levels? I'm noticing as I build more apps, that the design of the new apps is held back a bit by the central file & I'm required to access it in a particular way (particularly - importing a global variable). If each app were silo'd a bit more, I'd have more flexibility to pass that information around as I saw fit.

What do you folks think.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Where to store application config?

Post by allspiritseve »

I think app-specific config sounds a lot more manageable. That also means you don't have to worry as much about namespacing config items.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Where to store application config?

Post by Benjamin »

allspiritseve wrote:I think app-specific config sounds a lot more manageable. That also means you don't have to worry as much about namespacing config items.
I agree, each application is it's own entity and should therefore have it's own configuration file, it's own database etc. There may be a situation where all applications need global configuration options set. Those options, and only those options should go into a central config that each application will include.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Where to store application config?

Post by Christopher »

I use separate files too. But sometimes I have them include a central file if there really is common settings. I think the applications should have a standard source for the configuration data, but have it abstracted or standardized enough that the application does not care what is behind the source of the data. A Config object works well for this.
(#10850)
User avatar
VirtuosiMedia
Forum Contributor
Posts: 133
Joined: Thu Jun 12, 2008 6:16 pm

Re: Where to store application config?

Post by VirtuosiMedia »

Why not make the config files object-oriented? Put the common information in the central config file and have each application config file extend it. You load exactly what you need and you don't rewrite code. Edit: I think this is what arborint was suggesting as well.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Where to store application config?

Post by pickle »

Well it's sounding pretty clear that app-per-app config is the way to go. Thanks for confirming my thoughts.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply