Programming with Configuration Files

Jul 13, 02:02 am
tags: , , ,

Recently I was working on developing an application that required a configuration file to setup. I considered several options for the file, keep it in the native language (PHP), make it plain-text or use XML. I didn’t like any of the options because the configuration has to be approved by certain stakeholders of the data at various stages throughout the life of the application.

XML is too hard to read for management-types. Plain text wasn’t all that easy to handle from a code perspective. I could have used a native language configuration file that read more like plain text (mostly comments, few directives, etc), but still was not liking it.

Then I remembered that when I played with Ruby on Rails it used something called YAML, and thought I’d give that go. It didn’t take too long at all to get the hang of writing the syntax for YAML. I then needed to find a way to process it with PHP. I found a few.

I started with the top entry on a Google search for PHP YAML. I found spyc, which is a very simple YAML class for PHP. I also found Syck, which is apparently more widely used and ported to several languages (although Ruby looks to be the primary focus). But I decided to download spyc, which appeared to geared toward PHP, gave it a whirl and instantly had what I needed. I liked it so much, I packaged it up for Fedora. I should probably also mention that I looked at JSON, but found YAML to be more complete and easier to read for what I needed to do. JSON is cool though in that it is a subset of YAML for the most part and works nicely with Python.



    1. Syck is much faster and more standards-compliant.
      http://pecl.php.net/package/syck




Add your comments

Please keep your comments relevant to this blog entry: inappropriate or purely promotional comments may be removed. To add hyperlink, please follow this example: "your link text":http://your.link.url