views:

272

answers:

2

I have a custom PHP framework and am discovering the joys of storing configuration settings as human-readable, simple XML.

I am very tempted to introduce XML (really simple XML, like this)

<mainmenu>
 <button action="back" label="Back"/>
 <button action="new" label="New item"/>
</mainmenu>

in a number of places in the framework. It is just so much more fun to read, maintain and extend. Until now, configuration was done using

name=value;name=value;name=value;

pairs, arrays, collections of variables, and so on.

However, I fear for the framework's performance. While the individual XML operations amount to next to nothing in profiling, they are of course more expensive than a simple explode() on a big string. I feel uncomfortable with simpleXML (my library of choice) doing a full well-formedness check on a dozen of XML chunks every time the user loads a page.

I could cache the XML objects myself but would like to 1.) avoid the hassle and 2.) not add to the framework's complexity.

I am therefore looking for an unobtrusive XML "caching" solution. The perfect thing would be a function that I can give a file path, and returns a parsed simpleXML object. Internally, it maintains a cache somewhere with serialized simpleXML objects or whatever.

Does anybody know tools to do this?

No extension-dependent solutions please, as the framework is designed to run in shared webhosting environments (which is the reason why performance matters).

A: 

Hi there i'm useing the Zend Cache for those kind of things and must say it's very fast got one page from about 2secs to 0.5secs down.

+1  A: 

You could transform the XML into your former format once and then check for modification time of the XML and the text file via filemtime. If XML is newer than the textfile, then do the transformation again.

This would increase complexity in a way, but on the other hand would help you reuse your existing code. Of course, caching is another viable option.

Residuum