Answer the question
In order to leave comments, you need to log in
How to properly organize the storage and reading of site settings?
Actually, I'm developing a site in php. Faced with the eternal issue of storing site settings. Options considered: mysql base and ini files.
But the question is, if you store the settings in the database, then when reading from the database, we make a request. And if you need to read 30 settings, then there will be +30 requests, which will affect performance with a large attendance.
Or is it worth making a request to the database alone and extracting all the necessary data at once, and then only substitute them where necessary?
And if we consider ini files, then it also turns out there every time the settings are called, it is necessary to read the file every time and each time extract one field we need. Or is it better to read the entire file at once and retrieve what you need from memory? Then the memory is clogged in my opinion .. how then to be? How to properly organize settings and read them?
Please consider initially storing a thousand fields in the settings (as it usually happens in cms).
Answer the question
In order to leave comments, you need to log in
Good afternoon,
Then I will offer my option. Store the settings in a serialized form: as soon as the site opens, it checks for the existence of a file (for example: settings.dat), if the file is found, it reads it and does unserialize - the output is an array of settings. If there is no file, make a request to the database (as @VasiliyIsaichkin suggested ) and then save the resulting array of settings to a file (for example, settings.dat) via the serialize function + every time you change the CMS settings - delete the settings.dat file and it will be synchronized with the database again .
Good luck!
Since such questions are asked, I think that 30+ queries to the database is not the biggest cant on the future site.
Keep at the beginning of the file the index dot pohape and be done with it.
If the settings are rarely changed, then read the entire file file. About memory - you do not correlate the cost of it well, you will have 1-2 kb, the connection to SQL will eat much more.
You optimize in the wrong place and don’t think about it. 30+ requests are generally some kind of nonsense.
For highload, you can use some NRSHD like redis...
Store the settings either in the database or in a php file. Some hostings do not allow access to php.ini.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question