1

So currently I have a small web application that loads, processes, and displays a very large xml file (in excess of two megabytes). Unfortunately, especially along with the post-processing that takes place, the request takes around 6-7 seconds to load. Is there any way to speed up the loading of the xml file? The simplest way I can think of would be to load the XML file once into memory and then access that memory each request, but I'm not sure how to do that in PHP. From what I understand about the technology, using FastCGI should work, but again I'm unaware about how to go about constructing the necessary infrastructure to make it work.

So, I guess, what would everyone recommend to speed up the site? I'm, unfortunately, wedded to the idea of XML files at this point, and the transition to databases would be quite ugly (it's very tree based). But anything people could recommend will help.

4
  • How are you loading and processing the xml file? Commented Jul 13, 2011 at 17:38
  • Try APC: php.net/apc It may help, though serializing the DOMdocument object into APC may end up being slower than just re-parseing the xml each time. You'd have to test and see what happens. Commented Jul 13, 2011 at 17:38
  • Yeah XML is pretty ugly in comparison to other back-end data containing solutions. Are you saying you would like to keep a page from hanging upon a user loading a page on your site? Is the XML file loading causing the hanging? Commented Jul 13, 2011 at 17:38
  • Sorry, code is under copyright. I'm loading it with whatever PHP's DOM—not great, but passable. APC looks promising enough to try. And I'd be willing to go for an option where there was a page displayed to the user while data was loaded on the server end. Commented Jul 13, 2011 at 17:47

1 Answer 1

3

Read the XML file with XMLReader as it is pretty fast and make sure you use LIBXML_COMPACT and/or LIBXML_PARSEHUGE for reading. If your XML files dont change that often, consider Caching (for instance with memcached). Also, use a bytecode cache (like APC).

Most important: use a Profiler to make sure it really is the XML processing taking too long.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.