开发者

PHP - retrieving application settings once from INI, but where should I store it for global use?

开发者 https://www.devze.com 2023-02-12 09:53 出处:网络
I am writing a very large application that requires an initial query of a DB or INI file to retrieve application settings.I then want to store it once globally so that I don\'t have to keep querying a

I am writing a very large application that requires an initial query of a DB or INI file to retrieve application settings. I then want to store it once globally so that I don't have to keep querying a DB or reading an INI file for every page load.

I have a pseudo bootstrap file that I include in every PHP file. Inside this bootstrap file, I initiate application paths, setup the session etc. I also want this file to perform the intial DB or INI read and store the application settings globally. I was thinking of using $_SESSION but I'm not so sure if this is a good idea or not.

The type of data that I want to store once globally: directory integration credentials (AD, Kerberos, etc), whether or not the server instance is behind a proxy, DB connection credentials, and whether or not logging is enabled or not. Additionally, I want the user to have deep control on what logs to keep: i.e. "when users log in", "when there is an error", "when a new calendar event is created", etc. These various logging actions occur throughout my application and I don't want to query the DB or read an INI each time to check whether a particular logging setting has been enabled.

Here is what I was thinking re: SESSION vars:

if( !isset($_SESSION["settings_retrieved"] ){
// begin DB or INI read here
$_SESSION["use_proxy"] = 1;
$_SESSION["ad_user"] = "authorized_user001";
$_SESSION["log_login"] = 1;
$_SESSION["log_error"] = 1;
// etc...
}

What do you think? Shoul开发者_运维知识库d I store these global application variables in SESSION?


your ini file is already a storage you're looking for.
So, keep it - you don't need anything else.

Sessions is not something ethereal. It's the same file or database record. So, you're going to make that filesystem or database lookup anyway, making your system overcomplicated with no real gain.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号