fsockopen,fopen,file_get_contents 为什么fsockopen是最快的呢
query_time_class.inc.php
<?php
class query_time_class{
var $start_time;
var $end_time;
function query_start(){
$this->start_time = 0;
$this->end_time = 0;
$this->start_time = $this->get_cur_sec();
}
function query_end(){
$this->end_time = $this->get_cur_sec();
}
function get_query_time(){
$time = floatval($this->end_time - $this->start_time);
$time = sprintf("%01.4f",$time);
return $time;
}
function get_cur_sec(){
list($msec,$sec) = explode(" ", microtime());
$msec = floatval($msec);
$sec = floatval($sec+$msec);
return $sec;
}
function out_put(){
$time = $this->get_query_time();
$output = "执行时间 {$time} 秒";
echo $output;
}
}
?>
<?php
include('query_time_class.inc.php');
$query_time_obj = new query_time_class();
$query_time_obj->query_start();
for($ii=0; $ii<10; $ii++) {
fsockopen('www.poco.cn',80, $errno, $errmsg);
}
$query_time_obj->query_end();
echo("fsockfopen:");
$query_time_obj->out_put();
echo("\n");
$query_time_obj->query_start();
for($ii=0; $ii<10; $ii++) {
fopen('http://www.poco.cn',"r");
}
$query_time_obj->query_end();
echo("open:");
$query_time_obj->out_put();
echo("\n");
$query_time_obj->query_start();
for($ii=0; $ii<10; $ii++) {
file_get_contents('http://www.poco.cn');
}
$query_time_obj->query_end();
echo("file_get_contents:");
$query_time_obj->out_put();
?>