你还在用file_get_contents()吗

main.php 

代码:
<?php
$url = 'http://www.baidu.com';
$time_total = 0;

for($i = 0; $i < 100; $i++){
$time_start = get_time();
get_html($url);
$time_end = get_time();
$time_spent = $time_end - $time_start;
$time_total += $time_spent;
echo "counter:{$i} time:{$time_spent}\n"; 
usleep(200000);// 0.2 sec
}
echo "Total time:{$time_total}\n";

function get_time(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
第一个get_html()实现 

代码:
function get_html($url){
return file_get_contents($url);
}
测试情况.

第二个get_html()实现

代码:
function get_html($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$html = curl_exec($ch); curl_close($ch);
return $html; }

测试情况

FROM:http://www.hostloc.com/thread-88585-1-1.html

 

posted @ 2012-08-05 14:23  高级园长  阅读(144)  评论(0编辑  收藏  举报