Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 
Webmaster Blog

Why you should be using YAML for config

The vast majority of PHP applications out there use native PHP files for configuration. One or more standard PHP files declares a number of variables used for configuration. Given the syntax constraints of PHP - e.g. you can’t put a quote inside quoted values - a culture of developers insisting on managing config files is pretty much standard. But it doesn’t have to be.

YAML, or YAML Ain’t Markup Language, is a “human friendly data serialization standard”. It’s essentially a very basic format for storing data, and uses far less syntax than standard PHP. Here’s a sample of YAML:

---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
An error has occurred.

As you can see, it’s almost like English; it’s as basic as you want. Of course, that’s not to say it doesn’t support complex structures - this example demonstrates the power of the format.

Now, this is all well and good, but what does it mean for us as developers? Well, quite a lot, it seems:

  1. Our configuration files can finally be read - and modified! - by anyone.
  2. We can finally really start using config files, instead of database values with complex admin panels
  3. Config files are no longer as error prone as they used to be; forgetting to escape a quote in a config value won’t accidentally bring down your live application.
  4. The marketing guy can change ad positions in the company’s website himself, without having to call the poor IT guy at 1am.

Of course, there are also performance considerations of interpreting a specialised format as opposed to using native programming code. Thankfully, spyc, one of the best PHP YAML interpreters, is pretty damn fast.

Now that we have reliable config files, why not use them? Next time you’re building an application, instead of building some complex config manager in the admin panel, consider just using YAML.

Tags: ,


Related Posts
» Hacking Wordpress When You’ve Forgotten Your Password
» New features for Wordpress 2.6
» 5 Ways to be a Better PHP Developer
» Debugging CakePHP applications in Zend Studio for Eclipse
» And the winner of the most important security tip competition is…
 



Leave a Reply

Advertise with Us!


Blog Categories Blog Archives


Tutorials Scripts Web Hosting Developer Manuals
Resources