dongxin1980 2011-02-22 17:24
浏览 30
已采纳

PHP - 从INI检索一次应用程序设置,但是我应该在哪里存储它以供全局使用?

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? Should I store these global application variables in SESSION?

  • 写回答

1条回答 默认 最新

  • doushou1298 2011-02-22 18:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集