Jump to content

domDocument reallyyyy sloww


ohdang888

Recommended Posts

so in order to get the rss url of a blog (from its blog url), i found and tweeked this simple function below

 

It works... but its INCREDIBLY slow.. takes like 5-10 seconds sometimes.

 

Any ideas on how else to better go about this?

function getRSSurl($link)
    {
        $ret = array();
        $dom = new domDocument;
        @$dom->loadHTML(file_get_contents($link));
        $dom->preserveWhiteSpace = false;
        $tags = $dom->getElementsByTagName('link');
    
        /*** loop over the links ***/
        $x = 0;
        foreach ($tags as $tag)
        {
            if(strtolower($tag->getAttribute('rel')) == "alternate" && strtolower($tag->getAttribute('type')) == "application/rss+xml"){
            $ret[$x] = array('title' => $tag->getAttribute('title'), 'href' => $tag->getAttribute('href'));
            
            } 
          $x++;  
        }
    return $ret;
    }

$data = getRSSurl('http://www.example.com/blog/2010/05/22/this-is-the-title-of-the-2nd-post/');

foreach($data as $key=>$tag){
echo $tag['title']." ".$tag['href'];
}

Thanks!

Link to comment
Share on other sites

When fetching a remote file it typically won't be very fast. In my experience I haven't found there to be much of a time difference between cURL and file_get_contents, but you can give it a shot.

agreed. And if i use either of those, i have to use regex to find the link tags and grab those attributes... which is sure to be just as slow

 

Link to comment
Share on other sites

I used File_get_contents,  to grab data, and the script took over 10 seconds to load. Upon using cURL, it takes on average 2-3 seconds. It's a vast improvement from my experience.

are you saying you used the code i posted? or your own script?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.