user10470
user10470

Reputation:

What is an elegant way to speed up the loading/processing of XML in PHP?

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.

Upvotes: 1

Views: 855

Answers (1)

Gordon
Gordon

Reputation: 316969

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.

Upvotes: 3

Related Questions