简体   繁体   English

什么是加快 PHP 中 XML 的加载/处理的优雅方法?

[英]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).所以目前我有一个小的 web 应用程序,它加载、处理和显示一个非常大的 xml 文件(超过两兆字节)。 Unfortunately, especially along with the post-processing that takes place, the request takes around 6-7 seconds to load.不幸的是,尤其是在进行后处理时,加载请求大约需要 6-7 秒。 Is there any way to speed up the loading of the xml file?有什么方法可以加快 xml 文件的加载速度? 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. 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.根据我对该技术的了解,使用 FastCGI 应该可以工作,但我不知道如何构建必要的基础设施以使其工作。

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).不幸的是,此时我对 XML 文件的想法很感兴趣,并且向数据库的过渡将非常难看(它非常基于树)。 But anything people could 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.使用XMLReader读取 XML 文件,因为它非常快,并确保使用LIBXML_COMPACT和/或LIBXML_PARSEHUGE进行读取。 If your XML files dont change that often, consider Caching (for instance with memcached).如果您的 XML 文件不经常更改,请考虑缓存(例如使用 memcached)。 Also, use a bytecode cache (like APC).此外,使用字节码缓存(如 APC)。

Most important: use a Profiler to make sure it really is the XML processing taking too long.最重要的是:使用 Profiler 确保它确实是 XML 处理时间过长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM