Jump to content

Why is this MUCH faster than file_get_contents?


devWhiz

Recommended Posts


$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?

 

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.