MYSQL -> PHP -> XML/XSLT

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
dragobert
Forum Newbie
Posts: 2
Joined: Wed Jul 25, 2007 5:24 am

MYSQL -> PHP -> XML/XSLT

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
dragobert
Forum Newbie
Posts: 2
Joined: Wed Jul 25, 2007 5:24 am

Post 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??
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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)
Post Reply