NYCPHP Meetup

NYPHP.org

[nycphp-talk] Framework Question - Site Configuration

Nasir Zubair lists at ny-tech.net
Tue Dec 9 18:49:13 EST 2003


I have used both the CONSTANTS and array. To be frank, arrays have proven to
be a PITA. And as Jeff has pointed out, they stand out from rest of the code
being in all caps.

Put 'em all in one text/php file, and use auto_prepend:

php_value auto_prepend /home/usr/includes/config.inc  (with correct path to
inc file ).

If you rather stick with your current setup, you can try to transfer all the
directives from httpd.conf to a local .htaccess file, that way your
directives will not be in affect globally. 

- Nasir


> -----Original Message-----
> From: Alan T. Miller [mailto:amiller at hollywood101.com] 
> Sent: Tuesday, December 09, 2003 4:17 PM
> To: talk at lists.nyphp.org
> Subject: [nycphp-talk] Framework Question - Site Configuration
> 
> 
> 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
> 
> 




More information about the talk mailing list