Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to store configurations for php app -- xml or ini or db [closed]

I've got an app written in PHP, and there are a number of configurable variables. We're implementing a feature where the user can create sets of configurations and easily switch between them. How should I store my configs? as XML? in a .ini file? in multiple .ini files? in a db?

What's going to provide the most flexibility if we add fields down the road? Coding convenience?

If I use a db, I'll have to use a separate one from the app's main one for reasons that aren't worth going into, which has made me shy away from that. (Also, we're using .mdb files for our db.)

I've been going down the xml route, but I'm having problems with adding and editing configs using SimpleXML. Also, the app has to be compatible with php 5.1.6, and I'm a little nervous about some of the functionality.

Never really dealt with creating custom ini files....

A small clarification: the users won't touch the files -- they're non-techie. So setting up the initial files will be done by us, but then we're writing a tool that is going to writie out their configuration(s) to whatever format we choose.

like image 215
sprugman Avatar asked Apr 28 '09 15:04

sprugman


People also ask

Where can I find the configuration file of PHP?

Configuration of php.ini file: Whenever we install PHP, we can locate the configuration file inside the PHP folder. If using xampp, we can find the configuration file in one or many versions, inside the path ‘\xampp\php’. Note: Other versions of this file are php.ini-development and php.ini-production.

What is the most important PHP configuration file and why?

Whether you’re a PHP beginner or a seasoned developer, I’m sure that you’ve heard of php.ini: the most important PHP configuration file. When PHP is run, it looks for the php.ini file in some specific locations and loads it. This file allows you to configure a few important settings that you should be aware of.

Where is the PHP INI file located?

This can be tricky—the location of the php.ini file vastly varies by the environment you’re running PHP with. If you’re running Windows, you'll likely find the php.ini file within the directory of your PHP installation in the system drive.

Do I need to modify the settings in PHP?

Quite often, you’ll find you need to tweak settings in the php.ini file. On the other hand, it’s certainly possible that you've never needed to modify php.ini. PHP can run happily with the settings provided in the default php.ini file, since PHP ships with these default recommended settings.


2 Answers

I would store the configurations items in a PHP file. This is the most flexible method I have used.

$config['website_url'] = 'google.com';

I then have the following file structure

- config/development
- config/production

I have a constant defined early in the software named IN_PRODUCTION, when this is TRUE it loads up the production configuration items and vice versa.

This is simple and easily maintainable.

-Mathew

like image 90
The Pixel Developer Avatar answered Sep 24 '22 02:09

The Pixel Developer


Storing the settings for one DB in a different DB does not make much sense, IMO.

I would choose either an ini file, an xml file, or a php file, as proposed by jmucchiello. Each option has it's pros and cons. As for xml versus ini, xml offers more flexibility but is more difficult to maintain (less readable). If your needs are covered by ini, stick with the simpler solution. Use xml only if you need more than ini files can offer you.

As for the php solution, I would rate the readability somewhere between ini and xml, but it would be more difficult to save the current settings. So as much as I like the approach, for your current scenarion I would not recommend it.

like image 38
Treb Avatar answered Sep 26 '22 02:09

Treb