• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

Why you should be using YAML for config

By Akash Mehta | on Jan 25, 2008 | 0 Comment
PHP Tutorials
  • Tweet
  • Share
  • Tweet
  • Share

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.

Share this story:
  • tweet

Tags: PHP Tutorialsyaml

Author Description

No Responses to “Why you should be using YAML for config”

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 1,241Followers 494Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.