1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Rep Power

    PHP RSS Grabber very slow


    I have a script that grabs the latest two posts from my blog (on the same server) and displays them on my website.

    I am currently only testing this locally, but it still can takes up to 6 seconds to load due to this script, which I cannot understand why.

    Here is the script:

    PHP Code:
    = new DOMDocument();
    $feed = array();
                        foreach (
    $rss->getElementsByTagName('item') as $node) {
    $item = array ( 
    'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
    'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
    'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
    'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
    $limit 2;
    $x=0;$x<$limit;$x++) {
    $title str_replace(' & '' &amp; '$feed[$x]['title']);
    $link $feed[$x]['link'];
    $description $feed[$x]['desc'];
    $description substr($description0240);                        
    $date date('l F d, Y'strtotime($feed[$x]['date']));
    '<strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
    The script works great, but I can't see why it would be so slow, especially locally.

    All help is appreciated!
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    How long does http://localhost/lmb/blog/feed take to load?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Rep Power
    It's instant. At most a second. I had this in mind and tried to see if sometimes it did arbitrarily take longer, but there were no significant results from doing this (i.e. it was always below 1 second).

    Also, what I did as a test was save the RSS feed and put it in the root directory and used that URL. This meant it was a static file that wasn't going to change (rather than a file generated on request) and it was still slow, which I why I presumed it was a code issue.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Rep Power
    how about if you take away the two for & foreach loops and just dump the rss..

    (just to see maybe for & foreach timings)

    or alternatively, you could put timings in between each action and echo out to see which one takes longer

IMN logo majestic logo threadwatch logo seochat tools logo