user191766
user191766

Reputation:

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 of 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.

Upvotes: 1

Views: 752

Answers (4)

anon
anon

Reputation:

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.

Upvotes: 0

Colonel Sponsz
Colonel Sponsz

Reputation: 1721

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.

Upvotes: 4

Jade Robbins
Jade Robbins

Reputation: 163

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.

Upvotes: 2

Felix Kling
Felix Kling

Reputation: 816364

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...

Upvotes: 0

Related Questions