Jump to content

[SOLVED] reading xml faster than DB call?


abazoskib

Recommended Posts

I am trying to optimize a high traffic website, and I enabled a feature where there are three photos selected from the most recently submitted ones, and displayed at the top of the page. I figured that if each person is asking for 3 photos every time the page loads, this will put strain on server load. My solution involves having a script generate an xml file of the 30 most recent photos every half hour, and then cycle through the xml on the actual page. Is this a better solution than making a db call, in terms of speed gained/efficiency? I dont have much experience with XML so I wouldn't know how fast parsing it in PHP would be compared to a database call.

Link to comment
https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/
Share on other sites

I haven't actually run a test, I think it would depend on the XML format, but in general I think the XML should be faster because it doesn't involve communication between PHP and the DB.

 

However, I generally try to tell myself "keep it simple stupid" when it comes to programming. Why use XML when you could just as easily create a txt file with a list of image URLs separated by a spacer? You could explode the string into an array and choose a random index in the array. Would probably be much faster than parsing an XML file (once again, haven't tested to confirm).

XML is primarily designed to transport data between dissimilar applications.

 

Within a single application, where you are both producing and consuming the data using the same programing language on each side, using XML is just adding unnecessary overhead. So, if your primary goal is performance, don't use XML.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.