开发者

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 coul开发者_如何学God recommend will help.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜