Every time a page is loaded I connect to the database to fetch the settings table where the basic application settings are stored. It looks uneficcient. I have an idea to temporary store the $settings array in $_SESSION variable. So every time the script is started it checks if $_SESSION[‘settings’] is empty and loads the data from DB only if it is.
My questions are:
1)Is this normal practice or there are serious pitfalls?
2)Will this speed up my application?
I would guess performance benefits of this would be negligible at best, and potentially harmful at worst.
Either way $_SESSION isn’t really intended to be used this way, it’s for data relating to a specific user, and as a general rule I try to keep it as concise as possible.
A better solution you might consider is caching the settings locally as a PHP file, it’s not too hard to script something up to generate a file that creates a simple key => value array from the database that you can include. e.g.
Then you can just include this file to get your config values: