PHP - Application config file stored as - ini,php,sql,cached,php class,JSON,php array?

后端 未结 10 786
死守一世寂寞
死守一世寂寞 2020-12-13 14:15

I am trying to decide on the best way to store my applications configuration settings. There are so many options.

The majority of applications I have seen have used

10条回答
  •  有刺的猬
    2020-12-13 14:56

    I find Zend_Config to be a good solution. You can load the configuration from a simple array, from an INI style file, or from an XML document. Whichever you choose, the configuration object is the same, so you can switch storage formats freely. Zend_Config objects can also be merged, depending on your application this may be useful (a server config, then a per site/installation config).

    As with most (or all) things in the Zend Framework, you can easily use Zend_Config by itself.

    Considering efficiency, I'd say the fastest method would be to use an array, since that requires less (in this case no) string parsing. However, a INI/XML format may be easier for some to maintain. Of course some caching would give you the best of both worlds.

    Also, using INI files with Zend_Config allow you to define sections of configurations that inherit from each other. The most common use is a 'development' section that inherits from the 'production' section, then redefines the DB/debugging settings.

    As for security, keeping the config file out of the web root is the first step. Making it read only and limiting access could make it more secure; however, depending on your hosting/server configuration you may be limited in what can be done there.

提交回复
热议问题