I'm using php.ini (on nginx) to store database access credentials for PHP, aiming to get this data out of .php files.
I'd like to set global constants with these values once (only) and make them accessible to all scripts.
I'm currently doing as shown below, this script is require_once() by the database interface script. It works, but on the next request or whenever a page calls the dbinterface script, the constants have to be defined again, possibly because of a scope issue (from what I can gather).
Is there some way, other than using APC, to define these just once?
<?php
if( !configLoaded() )
loadConfig();
function loadConfig()
{
$vars = array("A","B","C");
foreach( $vars as $v )
define( $v, get_cfg_var( "ubaza.cfg.$v" ) );
}
function configLoaded() //returns false as soon as the caller script exits
{
return defined("A") && defined("B") && defined("C");
}
?>