开发者

Loading the same XML data on all my PHP scripts

I'm currently working on a small-scale PHP website where all data are stored in one XML file and XSLT-transformed into HTML in a variety of ways. For 开发者_高级运维the user, the data are read-only, but the XML file will sometimes be modified by the site administrator.

For the moment, each PHP script loads the data from the XML file into a DOMDocument object. This is done on every script at every request, but this is certainly not the best and fastest way.

What approach would you suggest to reduce the overhead and have the XML data readily available without having to open the file each time, but taking into account the fact that the XML file can be modified?


The obvious solution springing to mind would be to use a Cache, for instance memcached. Cache the results of the method call to DomDocument::load(). Invalidate the cache whenever an admin changes the XML.

However, you should profile your application first to make sure your current solution really has any negative and noticeable impact on your application. File I/O and XML parsing can be a bottleneck, but you should find out first, if it really matters.


You can cache your application in a number of ways:

Memcached is a good solution for caching. For a smaller site caching to a text-file might also work. If the data loaded is small you may even consider serializing an array and putting it in a session, but I'm not sure I would recommend this unless the amount of data is really small.

If the amount of data being read from the XML file is rather small I'd just stick with your current solution tho..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜