Page 1 of 1

MYSQL -> PHP -> XML/XSLT

Posted: Wed Jul 25, 2007 5:53 am
by dragobert
Hi,

This issue has already been discussed, I think. Nonetheless I want to ask you about my own problem concerning a design pattern I want to implement.

I want to separate PHP from the view.
Therefore I transform the data received by the DB into XML and use XSLT for styling it.
I have to mention that I would need to convert the XML into .csv or .xls, .pdf, .doc for exporting purposes.

Now I'd like to ask you if this approach affects the performance in a very negative way (I know that it affects it in a negative way but how much??) or if it could be a very modern approach.

IMHO I like the pattern but doubt that it will be very fast.

I'd like to give you more information about my plans:

There is a central .map.xml for every entity which serves for automated input processing and validation. Furthermore I'd like to use these Mapping files for creating the DB and INPUT-VIEWs.

For the Views - such as lists or single views - I would generate .xml templates, whose tags are the names of the DB-cols...
These xml templates are filled with DOM.

Now tell me what you think of that.

I appreciate any comment.


Cheers,

Peter

Posted: Thu Jul 26, 2007 7:11 am
by timvw
In my experience, we couldn't cache the xml, and thus we couldn't case the result of the xml after xsltranslation either, performance was really terrible... When we tried the XML/XSL approach we noticed that the same webserver could only handle a 10th (optimistic) of what it used to handle.... (especially memory-wise xml processing is a resource hog)

Posted: Fri Jul 27, 2007 2:38 pm
by Ambush Commander
After an interesting discussion on XSLT versus some other methods, I looked into some ways to improve the performance of XSLT. Here's what I found:

- Cache results
- Cache stylesheets in memory (I'm not exactly sure how to do this, but it should not be necessary to parse an XSLT file every time you want to use it)
- Avoid re-processing large portions of the tree, the // (descendant) axis can be pretty inefficient in that respect
- Use variables instead of repeatedly accessing tree
- Sorting is slow
- Smaller is better
- Often, it will be a trade-off between modularity and speed

Courtesy of Java and XSLT by Eric M. Burke. Also, make sure the xmllib compiled in your PHP is fairly recent: there were some major performance improvements in some very recent versions that haven't been fully reflected, for example, in Cygwin.

Posted: Sat Jul 28, 2007 8:24 am
by dragobert
Thank you for you replies!

Well, I think I'll keep working on my approach. I lack experience and therefore I'll just try it out :-)

@Ambush Commander:

As I said, I lack experience and some in-depth knowledge about WEB-Techs.
As a result I have no clue how caching actually works -> is it saving a temporary file that is only updated if its content changes??

Posted: Sat Jul 28, 2007 10:30 am
by Charles256
The way I implement it is whenever the database is modified that holds the content for the XML I generate the XML page again and on the pages that call the XML I check to see if the file is more than four hours old, if so, create a new one. Is it really necessary to do the latter part? No, but I am paranoid. :-D

Posted: Sat Jul 28, 2007 5:11 pm
by Ambush Commander
As a result I have no clue how caching actually works -> is it saving a temporary file that is only updated if its content changes??
In essence, yes, for result page caching. For XSLT stylesheet caching, it's a bit more complicated.

Posted: Sat Jul 28, 2007 5:32 pm
by timvw
Something i seem to hear a lot from people using XML/XSL is that they explicitly have a caching strategy..
(Imho, this seems to confirm that there really is a performance issue compared to templates in php)

If your XSL doesn't have to take care of security (hiding 'secured' data) you can also offload the xsl transformation to the consuming user-agent... (which in my experience this works pretty well)