开发者

loading xml slows down my site

is it possible that loading an xml is slowing down my site?

I've written this little function in php to iterate over an array of Strings to calculate the total amount o开发者_StackOverflowf my followers

function getFeedCount() {
    foreach ($array as $value) {
        $xml = simplexml_load_file("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=$value")
                or die ("Unable to load XML file!");
        $circulation += $xml->feed->entry['circulation'];
    }   
    return $circulation;
}

the array is about 10 items big and since I started using it, it really slowed down my site.

What could I do fix this issue.


Loading the data from feedburner will be what's causing this: every time someone views your page it has to make 10 requests to the feedburner server for the feeds before it can return any data to your visitor.

Probably the best way round this is to cache the feedburner feeds to your server periodically and read the cached copies in the page generation.


It absolutely can slow down your site. Being it's not an asynchronous operation, the entire creation of that page is waiting on that XML to get downloaded before it can finish anything else.

Depending upon how much the XML changes, people do a local cache of the XML data and do a periodic grab to update. The upside to this is that for most page views you are grabbing the resource locally, the downside is that it isn't real time data.

Another option is to try and use javascript to load the xml data after the page has loaded, but the downside to this process is that your PHP doesn't have access to the XML data.


Is the number changing that often? Maybe you can cache it (e.g. store it in a file) and only get the feeds once a day (via e.g. cron job).

I mean, accessing URLs takes time. It is like your visitors are accessing 10 pages before they can access yours...


Making an HTTP request on every page load is very costy, it's totaly normal that your site is slown down.. the best aproach for this would be to write an XML parser that supports caching.

you can use this PHP API too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜