PHP and XML
I am developing a website with users using some XML.
I would like to know what is the best and must optimized way to read and write XML with PHP. Currently I made some test with " new DOMDocument();" it work well but is it the best way to do it?
And is it best to read a big XML that contain many info or to split it in many little XML that contain less info, and to read them one after the other?
And do you have any good tips of PHP optimizations, what not to do or use and what to make to optimize.
One last question, what happen if a user must update an XML and at the same time an other user must write in the same XML? It will create a conflict, anyone have ideas to solve that problem?
Last edited by narolis; 02-10-2009 at 05:35 PM.
If you have these questions then I recommend using a database or serialised text file, XML is much less efficient.
It really depends on the size of the XML file, there is an overhead for each file, but the size of the file is very important, where possible try to load as little as possible.
simpleXML is not the most efficient method, but it is the most flexable. The most efficient method depends a lot on what you are doing, if you want to add a row, then it is faster to not use a lib, just edit the file with normal text editing functions. If you want to read the whole file and parse it multiple times, then it's better to use a multi-dimensional array and the xml_parse function.
XML is parsed once, edits once it's parsed will not have an effect, but an edit while it is being read might cause problems. That is why there is such a thing as a file lock, which should be used.
I would second the motion that the best way to store data that needs to be manipulated by users is via a database. It's going to be more efficient, plus it has the tools built into it for locking, transactions, etc. to avoid things like race conditions between concurrent users. If you need to provide XML output, that can be generated on the fly from the database as easily as HTML output can be generated.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread