devWhiz Posted April 9, 2011 Share Posted April 9, 2011 $HEADER = "http://www.google.com"; for($cwb=1; $cwb!=100; $cwb++) { $repeat = file_get_contents($HEADER); $msg = explode('<message>', $repeat); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } why is this much faster? $HEADER = "http://www.google.com"; $REPEAT = 100; // times to repeat $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); for($cwb=1; $cwb!=$REPEAT; $cwb++) { curl_setopt($ch, CURLOPT_URL, $HEADER); $msg = explode('<message>', curl_exec($ch)); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } while($ch); curl_close($ch); is there anything faster than both of these options? Quote Link to comment https://forums.phpfreaks.com/topic/233218-why-is-this-much-faster-than-file_get_contents/ Share on other sites More sharing options...
dcro2 Posted April 9, 2011 Share Posted April 9, 2011 Because curl is optimized for this purpose. file_get_contents and the other file functions that can get external urls are optimized for local files. Quote Link to comment https://forums.phpfreaks.com/topic/233218-why-is-this-much-faster-than-file_get_contents/#findComment-1199382 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.