I am building an RSS parser using the SimpleXML Class and I was wondering if using the DOMDocument class would improve the speed of the parser. I am parsing an rss document that is at least 1000 lines and I use almost all of the data from those 1000 lines. I am looking for the method that will take the least time to complete.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
SimpleXML
andDOMDocument
both use the same parser (libxml2
), so the parsing difference between them is negligible.This is easy to verify:
On my machine I get basically no difference:
The real issue here is what algorithms you are using and what you are doing with the data. 1000 lines is not a big XML document. Your slowdown will not be in memory usage or parsing speed but in your application logic.
Well, I have encountered a HUGE performance difference between
DomDocument
andSimpleXML
. I have ~ 15 MB big XML file with approx 50 000 elements like this:I only need to "read" those values and save them in PHP array. At first I tried
DomDocument
...That script died after 60 seconds with maximum execution time exceeded error. Only 15 000 items of 50k were parsed.
So I rewrote the code to
SimpleXML
version:After 1 second all was done.
I don't know how those functions are internally implemented in PHP, but in my application (and with my XML structure) there is really, REALLY HUGE performance difference between
DomDocument
andSimpleXML
.