NYCPHP Meetup

NYPHP.org

[nycphp-talk] Framework Question - Site Configuration

David Mintz dmintz at davidmintz.org
Tue Dec 9 17:18:17 EST 2003


On Tue, 9 Dec 2003, Alan T. Miller wrote:

>  <snip />
> I was thinking that it would may be easier to ditch this effort and go with
> a standard configuration file in PHP that I can include for the site and
> scripts that run outsode the virtual environment. Perhaps something like the
> following...
>
> <?php
>
> define(DATABASE_NAME,'somedatabase');
> define(DATABASE_USER,'someuser');
> define(LINK_SITE_MAP,'/site-map.php');
>
> ?>
>
> and then access the values in the script using their constant values or
> perhaps store the values in an array such as...
>
> <?php
>
> $site = array(
> 'DATABASE_NAME' => 'somedatabase',
> 'DATABASE_USER' => 'someuser',
> 'LINK_SITE_MAP' => '/site_map.php'
> );
>
> ?>
>
> I would like to hear all your thoughts on this issue. I have about 100
> configuration directives I would like to be able to store in one place. I
> would be curious how others have dealt with simular issues. Are there
> advantagaes to using an array for config values as mentioned above over lets
> say defining constants?


One thing I have experimented with is saving configs in a plain text
config file in the format that parse_ini_file likes. Then you can do this
if you want

$cfg = parse_ini_file('/path/to/config.conf');
foreach($cfg as $key => $value) {
	define($key,$value);
}

...or not. Works for me.

One nice thing is that you if you happen to use Perl as well for some
reason, there's the Config::General module that can also read the same
config file. (The one gotcha is the different comment syntax). In any case
you should be able to achieve the objective of centralizing the config
info.

But I've seen other apps use both of the approaches you refer to above.
TMTOWTDI, as they say.

HTH,

---
David Mintz
http://davidmintz.org/


        "Anybody else got a problem with Webistics?"

                Sopranos 24:17



More information about the talk mailing list