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
https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/
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

 

Archived

This topic is now archived and is closed to further replies.

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