I tried this little test:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set('max_execution_time', 240);
function doCurl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$html = curl_exec ($ch);
curl_close ($ch);
return($html);
}
function doFgc($url)
{
return(file_get_contents($url));
}
microtime(true); // get timer in cache
$runTimes = array();
$url = "http://www.charles-reace.com/";
$start = 0;
$end = 0;
$runs = 10;
$startix = rand(0,1);
$runs += $startix;
for($i=$startix; $i<=$runs; $i++)
{
if($i % 2) // alternate sequence methods used
{
// cURL:
$start = microtime(TRUE);
$html = doCurl($url);
$end = microtime(TRUE);
unset($html);
$runTimes['curl'][] = $end - $start;
// file_get_contents:
$start = microtime(TRUE);
$html = doFgc($url);
$end = microtime(TRUE);
unset($html);
$runTimes['fgc'][] = $end - $start;
}
else
{
// file_get_contents:
$start = microtime(TRUE);
$html = doFgc($url);
$end = microtime(TRUE);
unset($html);
$runTimes['fgc'][] = $end - $start;
// cURL:
$start = microtime(TRUE);
$html = doCurl($url);
$end = microtime(TRUE);
unset($html);
$runTimes['curl'][] = $end - $start;
}
}
printf("<p>Total time for cURL: %.6f sec, average: %.6f sec.</p>\n",
array_sum($runTimes['curl']), array_sum($runTimes['curl']) / $runs);
printf("<p>Total time for file_get_contents(): %.6f sec, average: %.6f sec.</p>\n",
array_sum($runTimes['fgc']), array_sum($runTimes['fgc']) / $runs);
A sampling of results:
Total time for cURL: 10.608718 sec, average: 1.060872 sec.
Total time for file_get_contents(): 7.226971 sec, average: 0.722697 sec.
Total time for cURL: 11.559411 sec, average: 1.050856 sec.
Total time for file_get_contents(): 8.025178 sec, average: 0.729562 sec.
Total time for cURL: 13.719659 sec, average: 1.247242 sec.
Total time for file_get_contents(): 8.441728 sec, average: 0.767430 sec.
Total time for cURL: 11.574428 sec, average: 1.157443 sec.
Total time for file_get_contents(): 7.953396 sec, average: 0.795340 sec.
So at least for the purpose of a one-time call to another site to get the html content of a page, I'll stick with file_get_contents(). (I suspect there may be an advantage to cURL if you are making multiple requests over the same connection, but for a one-off deal file_get_contents() appears to have the edge.)