Was just wondering if anyone had a good system for storing / updating dynamic settings in php?
What i mean by dynamic is settings that change automatically by other scripts.
Currently we use a system that basically file_get_contents our settings php file, treats that as a string, changes settings and file_put_contents the updated settings.
It works but its a bit dirty. Any other recommendations where we can store / modify / pull these settings from? Mysql is NOT an option, we want to avoid the extra queries.
As an added bonus, some system that can share this data over multiple servers as many of these settings are used across multiple boxes. But i suppose we can deal with that seperatly.
Thx!
Things to keep in mind if you stick with a file-based approach:
Using a native parser
A parser written in C will most likely be quicker than one in PHP.
The two options that spring to mind are
Use a
settings.phpfile, that contains well-formed PHP code. One approach I’ve used in the past is having a file that looks likeThis file can be
include-d one or more times, and theincludestatement will return the configuration array. When you’re writing the new settings, usevar_export()to get valid php code.The other approach is using a
settings.csvfile. Read usingfgetcsv(), write usingfputcsv().Avoiding "partial" saves
To avoid a partial file being read while the settings are being updated, first write the new settings to a temporary file, then move this file to the setting file location (preferrably using
mv (1)on *nix).