Alex Rivera | Logout

Fastest way to store easily editable config data in PHP?

Asked 2010-01-06T19:50:03.383
26

What is the fastest way to store config data in PHP so that it is easily changeable (via PHP)? First I thought about having config.php file, but I can't edit it on fly with PHP, at least not very simply? Then I thought about having XML files, but parsing them for each HTTP request is overwhelming. So, I thought about INI files, but then I figured that INI files are restricted to int/string values. In the end, I have come to the conclusion that JSON encoded file is the best:

$config['database']['host'] = ...;
$config['another']['something'] = ...;
...
json_encode($config);

Since JSON can store arrays, I can create quite complex configurations with it, and it parses faster than INI files.

My question: did I miss something or is there a better way to do this?

Edit
Report

1 Answer

2

You should use serialize as opposed to json_encode:

http://docs.php.net/serialize

answered 2010-01-06T19:52:26.430

Your Answer