NYCPHP Meetup

NYPHP.org

[nycphp-talk] Framework Question - Site Configuration

Jeff Siegel jsiegel1 at optonline.net
Tue Dec 9 18:00:32 EST 2003


Personally, I prefer using constants defined in a config file. Since, by 
convention, constants are normally all in CAPS, then mispelling a 
constant name immediately throws up a parse error. In addition, it's a 
visual indicator to me that its value has been set "somewhere" in my 
app. It would seem that using an array, one could inadvertantly change 
the value whereas once a constant is defined, that's that...no mucking 
around with its value.

Jeff Siegel

Alan T. Miller wrote:
> Framework question.
> 
> I had an idea that if I were to store many of the web site configuration
> values in the web server environment, such as database connection
> parameters, default email address, company address and major site links in
> each apache server virtual host environment, this information would be
> resident in the server memory, and subsequent requests would require less
> over head than creating a large configuration file that would be loaded and
> parsed at runtime each time a script on our site ran.
> 
> For example. In my apache config I set the values in the following manner...
> 
> setEnv    DATABASE_NAME    = "somedatabase"
> setEnv    DATABASE_USER    = "someuser"
> setEnv    DATABASE_PASS    = "somepass"
> setEnv    LINK_HOME_PAGE = "/index.php"
> setEnv    LINK_SITE_MAP = "/site-map.php"
> setEnv    EMAIL_DEFAULT = "info at foo.com"
> setEnv    EMAIL_SALES = "sales at foo.com"
> setEnv    PATH_PHOTOS = "/photos/"
> setEnv    PATH_GIFS = "/gifs/"
> 
> To access these from my scripts, I can use the following...
> 
> $_SERVER['DATABASE_NAME']
> $_SERVER['DATABASE_USER']
> $_SERVER['DATABASE_PASS]
> $_SERVER['LINK_HOME_PAGE']
> $_SERVER['LINK_SITE_MAP]
> 
> Because they are resident in the memory of the server, the server does not
> have to parse the file each time a request is made for the virtual host.
> 
> However, this is proving to be a pain because there are other scripts that
> run from CRON etc, that do not run from the virtual host environment, and
> for those scripts, I have ended up duplicating my efforts by creating
> another configuration file for our site. This means I have to update changes
> to the configuration twice.
> 
> 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?
> 
> Ideas, suggestions?
> 
> Thanks.
> 
> 
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
> 

-- 
Found on the Simpson's Website:
"Ooooooh, they have the internet on computers now!"




More information about the talk mailing list