Kevin Waterson has posted a new tutorial today looking at a key part of any web application - the configuration settings and how they can be stored.
PHP applications come in many shapes and sizes. Some used locally from command line, and more commonly, for web based applications. More often than not, regardless of size or type, some form of configuration variables will be stored for global access. [...] Each options has its pros and cons. Here each of these options is explored to see which method is right for your application.
He looks at four different options:
- an ini file that can be parsed/modified directly by PHP
- an XML file slightly more complex, but still simple for PHP to use
- a PHP file with things like PHP arrays defining settings
- and a database with one or more configuration tables
Each type comes with some example code and format to give you an idea of how they'd work.










I'm wondering what the performance impact would be if, instead of one setting, all settings would be retrieved from the database when there are one thousand sections with three entries.
With the methods of the ini file and SimpleXML, all settings are parsed at once and available in-memory and can be accessed immediately. With the database however, you'll have to make a call for each setting, or retrieve all settings at once.