Closed Thread Icon

Topic awaiting preservation: PHP: Best way to configure a site. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27035" title="Pages that link to Topic awaiting preservation: PHP: Best way to configure a site. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP: Best way to configure a site. <span class="small">(Page 1 of 1)</span>\

 
zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-22-2005 00:22

I have been trying to find a good, flexible, portable, reliable way to configure a PHP website. So far I've been only stuffing all configuration vars in a $cfg array, but I don't know weather there's a better way or not.

Sould I...
use a config array to hold all config vars?
use the define() function to define all the config vars?
use a database table for config vars?
use a text/XML file to hold all the config vars and have PHP parse it?
use some other method?

How do you configure your PHP website(s)?

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 11-22-2005 01:13

If you look at most sites you will find that an array of variable tends to be used to store the configuration data. This will often be the fastest way to have your information stored, it will be immediately accessible to your forms.

I like XML, but this will require some additional overhead. I have never run numbers or stress tested this. You will find that there are many Pear modules that will allow you to parse your XML without having to roll your own parser.

A DB is IMO way too much overhead. It might seem nice, but you would need to store this data somewhere else for t he session so that you are not making repeditive database calls for every page that needs the config information. And you will still need a separate config to store your DB connection settings.

So XML or an Array. They have pro's and cons, but they will work.

Dan @ Code Town

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-22-2005 03:50

Ok, I think I'll stick with what I'm doing then and maybe look into XML at a later time.
Thanks WM!

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-22-2005 09:00

Config arrays or a lot of define('CONFIG_...') directives (loaded depending on HTTP_HOST, of course) and templates are usually the way to go.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-23-2005 21:40

Yes, I agree templates do help.
IMO using define() to set all the config vars is extra work and not very neat looking. Arrays I think are better because I can just define the whole array global in a function. I think define() should be used when theres a good chance you may get your vars crossed.

I like to abreviate everything to make them smaller, so an example config array var for the databse would look like:

code:
$cfg['db']['tbl'][2]





(Edited by zavaboy on 11-23-2005 21:43)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-24-2005 01:46

Actually I've used a combination.

I run the array through a key value loop to get globals. and then unset the array.

Doesn't really save me much except it seems better for me visually.

I agree XML parsing and DB entries seem like too much overhead.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu