Should a PHP app store configuration data in defined constants or a database?
I'm working on a PHP application and I keep going back-and-forth with
myself over the best way to store configuration data (the type that might
change occasionally, but probably not frequently). This includes mostly a
lot of non-sensitive information like validity periods for certain tokens
and cookies, or parameters for the various email messages the application
sends, but it also includes a few more sensitive things like API keys.
Store it in a database table - This is the path I initially started going
down, in part because I was imagining a handy administrative utility that
would allow system admins to easily modify these values when necessary.
But since most of the application pages need to access one or more of
these values, it just feels like a lot of excess trips to the database,
even if they are small, fast lookups.
Use defined constants - I also thought of just using defined constants and
sticking the data in a .php file (outside the web root, of course). This
would obviously avoid any database lookups, but somehow it feels similarly
wasteful to define a few dozen constants on every page load when a given
page will only need a handful of them at most.
Is one or the other (or something else altogether) recommended, whether it
be for reasons of security, efficiency, or simply style?
No comments:
Post a Comment