当前位置:首页 > PHP教程 > php高级应用 > 列表

php检测服务器的运行

发布:smiling 来源: PHP粉丝网  添加日期:2013-12-11 13:13:18 浏览: 评论:0 
  1. // 检测函数支持 
  2. function isfun($funName) { 
  3.  return (false !== function_exists($funName))?'支持':'<font color=red>不支持</font>'; 
  4. } 
  5. //整数运算能力测试 
  6. function test_int() { 
  7.  $timeStart = gettimeofday(); 
  8.  for($i = 0; $i < 3000000; $i++) { 
  9.   $t = 1+1; 
  10.  } 
  11.  $timeEnd = gettimeofday(); 
  12.  $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"]; 
  13.  $time = round($time, 3)."秒"; 
  14.  return $time; 
  15. } 
  16. //浮点运算能力测试 
  17. function test_float() { 
  18.  //得到圆周率值 
  19.  $t = pi(); 
  20.  $timeStart = gettimeofday(); 
  21.  for($i = 0; $i < 3000000; $i++) { 
  22.   //开平方 
  23.   sqrt($t); 
  24.  } 
  25.  $timeEnd = gettimeofday(); 
  26.  $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"]; 
  27.  $time = round($time, 3)."秒"; 
  28.  return $time; 
  29. } 
  30. //IO能力测试 
  31. function test_io() { 
  32.  $fp = @fopen(PHPSELF, "r"); 
  33.  $timeStart = gettimeofday(); 
  34.  for($i = 0; $i < 10000; $i++) { 
  35.   @fread($fp, 10240); 
  36.   @rewind($fp); 
  37.  } 
  38.  $timeEnd = gettimeofday(); 
  39.  @fclose($fp); 
  40.  $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"]; 
  41.  $time = round($time, 3)."秒"; 
  42.  return($time); 
  43. } 

Tags: php检测 服务器 运行

分享到: