首頁  >  文章  >  php教程  >  php检测服务器的运行能力

php检测服务器的运行能力

WBOY
WBOY原創
2016-06-13 09:58:09722瀏覽

php检测服务器的运行能力

// 检测函数支持
function isfun($funName) {
 return (false !== function_exists($funName))?'支持':'不支持';
}

//整数运算能力测试
function test_int() {
 $timeStart = gettimeofday();
 for($i = 0; $i   $t = 1+1;
 }
 $timeEnd = gettimeofday();
 $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
 $time = round($time, 3)."秒";
 return $time;
}

//浮点运算能力测试
function test_float() {
 //得到圆周率值
 $t = pi();
 $timeStart = gettimeofday();
 for($i = 0; $i   //开平方
  sqrt($t);
 }
 $timeEnd = gettimeofday();
 $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
 $time = round($time, 3)."秒";
 return $time;
}

//IO能力测试
function test_io() {
 $fp = @fopen(PHPSELF, "r");
 $timeStart = gettimeofday();
 for($i = 0; $i   @fread($fp, 10240);
  @rewind($fp);
 }
 $timeEnd = gettimeofday();
 @fclose($fp);
 $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
 $time = round($time, 3)."秒";
 return($time);
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn