ohdang888 Posted May 27, 2010 Share Posted May 27, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/ Share on other sites More sharing options...
-Karl- Posted May 27, 2010 Share Posted May 27, 2010 I find cURL to be much quicker when grabbing data from an outside source. Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064379 Share on other sites More sharing options...
Alex Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064380 Share on other sites More sharing options...
ohdang888 Posted May 28, 2010 Author Share Posted May 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064433 Share on other sites More sharing options...
ohdang888 Posted May 28, 2010 Author Share Posted May 28, 2010 maybe if i use this instead i could save the file_get_contents() function... but its probably the same either way $doc->loadHTMLFile("filename.html"); Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064434 Share on other sites More sharing options...
-Karl- Posted May 28, 2010 Share Posted May 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064436 Share on other sites More sharing options...
ohdang888 Posted May 28, 2010 Author Share Posted May 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064443 Share on other sites More sharing options...
-Karl- Posted May 28, 2010 Share Posted May 28, 2010 My own script. Quote Link to comment https://forums.phpfreaks.com/topic/203144-domdocument-reallyyyy-sloww/#findComment-1064459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.