smerny Posted March 10, 2010 Share Posted March 10, 2010 I have this simple code just to test/learn getting data from other webpages: <?php $raw = file_get_contents("http://services.runescape.com/m=itemdb_rs/Cactus_spine/viewitem.ws?obj=6016"); $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); $content = str_replace($newlines, "", html_entity_decode($raw)); $start = strpos($content,'<b>Market price:</b> ')+21; $end = strpos($content,'</span><span><b>Maximum price:',$start); $marketprice = substr($content,$start,$end-$start); echo $marketprice; ?> this code is taking over 30 seconds to load... is this normal for file_get_contents? the page that i am getting contents from will load at a decent rate when i go directly to that webpage.... so it's not that the page i am getting contents from is slow. Link to comment https://forums.phpfreaks.com/topic/194807-file_get_contents-extremely-long-load-time/ Share on other sites More sharing options...
schilly Posted March 10, 2010 Share Posted March 10, 2010 if you're loading external pages you probably want to use curl. i do anyways for anything external. Also if you switch servers, file_get_contents may not support external urls. by default i'm pretty sure it doesn't. you need to enable the fopen wrappers. Link to comment https://forums.phpfreaks.com/topic/194807-file_get_contents-extremely-long-load-time/#findComment-1024372 Share on other sites More sharing options...
smerny Posted March 10, 2010 Author Share Posted March 10, 2010 looked at the manual and there was way too much info on curl that didn't really do a good job at explaining what to do... searched google for curl screen scraping and found an example that i modified to fit my need... this is what i'm using now, works much faster. thanks. $ch = curl_init() or die(curl_error()); curl_setopt($ch, CURLOPT_URL,"http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=2355"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $raw=curl_exec($ch) or die(curl_error()); curl_close($ch); $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); $content = str_replace($newlines, "", html_entity_decode($raw)); $start = strpos($content,'<b>Market price:</b> ')+21; $end = strpos($content,'</span><span><b>Maximum price:',$start); $marketprice = substr($content,$start,$end-$start); echo $marketprice; Link to comment https://forums.phpfreaks.com/topic/194807-file_get_contents-extremely-long-load-time/#findComment-1024378 Share on other sites More sharing options...
roopurt18 Posted March 10, 2010 Share Posted March 10, 2010 If you're using PHP5 and have access to it, I'd recommend using HttpRequest instead of cURL. http://usphp.com/manual/en/book.http.php I primarily use: http://usphp.com/manual/en/class.httprequest.php It's really just a cURL wrapper, but I find it easy to use. Link to comment https://forums.phpfreaks.com/topic/194807-file_get_contents-extremely-long-load-time/#findComment-1024438 Share on other sites More sharing options...
schilly Posted March 10, 2010 Share Posted March 10, 2010 nice thanks roopurt18. I'll check that out next time I need to use curl. Link to comment https://forums.phpfreaks.com/topic/194807-file_get_contents-extremely-long-load-time/#findComment-1024449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.