abazoskib Posted October 19, 2009 Share Posted October 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/ Share on other sites More sharing options...
ialsoagree Posted October 19, 2009 Share Posted October 19, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/#findComment-939719 Share on other sites More sharing options...
abazoskib Posted October 19, 2009 Author Share Posted October 19, 2009 yes i thought about the text file, but i chose xml because it is a more "universal" format. so far i am seeing good results, i just wanted to hear other experiences. Quote Link to comment https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/#findComment-939728 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2009 Share Posted October 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/#findComment-939756 Share on other sites More sharing options...
abazoskib Posted October 19, 2009 Author Share Posted October 19, 2009 Great, thanks for the advice. Quote Link to comment https://forums.phpfreaks.com/topic/178235-solved-reading-xml-faster-than-db-call/#findComment-939773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.