Global $CONF vs archivo de configuración
Frecuentes
Visto 368 veces
0
I am a fresher to php. So forgive me, if my question seems wrong.
Recently we started developing a CMS for our client's use. The system is storing most of the configuration details in global $CONF
. For example the system stores the site name, site admin email, site statistics etc.. in this variable. When I used a print_r($CONF)
it was more than one page length.
My question is isn't it better to save these values in a php file as an array and include it, than saving all this in memory? What are the pros and cons for both?
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php memory global or haz tu propia pregunta.
The variable won't persist between script calls/requests unless it is stored in
$_SESSION
, in which case it will effectively be stored in a file as an array anyway (seeserialize()
). Can you expand on exactly what you mean here? Over what lifetime are you talking about keeping the variable? During a single execution call, or across multiple calls? - DaveRandom@DaveRandom : Thanks for the reply. I need these configurations through out the system. So isn't it better to include it as a single file on the initial system loading, immediately before the Database connection (The database connection is loaded in all pages)? So will this be faster and efficient than storing everything in a global $CONF? - Mic
If you store your config vars in a file they still need tobe loaded at some point into memory, if you store in a session then the session file will need tobe loaded. File operations tend tobe slower then memory cycles. - Lawrence Cherone
@Mic If it is possible to store something in memory, then that is generally the faster/more efficient way to do it, because disk reads are much slower than memory reads. However with what you are talking about here, it is not possible to store it just in memory (at least, not without an external program) so you will need it to be written to disk for it to persist between requests. It sounds like whatever you are doing at the moment would be the way to do it (although global variables are bad, you should pass the data explicitly between scopes). - DaveRandom
@LawrenceCherone +1 - FYI, "to be" cannot be legitimately concatenated to "tobe" in English :-P - DaveRandom