首页 > 开发 > PHP > 正文

php检测服务器的运行

2024-05-04 21:47:27
字体:大 中 小
来源:转载
供稿:网友
  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. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表