当前位置:论坛首页 > Linux面板 > 建议

控制台bug

发表在 Linux面板2017-1-19 11:48 [复制链接] 2 3323

Ajax.php里面GetCpuPercentages函数
  1. function GetCpuPercentages($stat1, $stat2) {
  2.         if(count($stat1)!==count($stat2)){
  3.                 return;
  4.         }
  5.         $cpus=array();
  6.         for( $i = 0, $l = count($stat1); $i < $l; $i++) {
  7.                 $dif = array();
  8.                 $dif['user'] = $stat2[$i]['user'] - $stat1[$i]['user'];
  9.                 $dif['nice'] = $stat2[$i]['nice'] - $stat1[$i]['nice'];
  10.                 $dif['sys'] = $stat2[$i]['sys'] - $stat1[$i]['sys'];
  11.                 $dif['idle'] = $stat2[$i]['idle'] - $stat1[$i]['idle'];
  12.                 $dif['iowait'] = $stat2[$i]['iowait'] - $stat1[$i]['iowait'];
  13.                 $dif['irq'] = $stat2[$i]['irq'] - $stat1[$i]['irq'];
  14.                 $dif['softirq'] = $stat2[$i]['softirq'] - $stat1[$i]['softirq'];

  15.                 $total = array_sum($dif);
  16.                 $cpu = array();
  17.                 foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 2);
  18.                 $cpus['cpu' . $i] = $cpu;
  19.         }
  20.         return $cpus;


  21. }
复制代码
$total计算出来的数字可能是0 后面除法错误  导致出现了一个 float(NAN)的数据  这个无法被json_encode 最后导致这个ajax无法请求到结果
然后首页请求不到结果 layer的遮罩层不会消失 无法做任何操作
多次刷新后会正常
使用道具 举报 只看该作者 回复
发表于 2017-1-19 18:24:39 | 显示全部楼层
经测试没有发现此问题
使用道具 举报 回复 支持 反对
发表于 2017-1-19 18:59:48 | 显示全部楼层
hitrun 发表于 2017-1-19 18:24
经测试没有发现此问题

从代码逻辑上看 会出现我说的问题
我之前那台服务器确实出现了
使用道具 举报 回复 支持 反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

企业版年付运维跟进群

普通问题处理

论坛响应时间:72小时

问题处理方式:排队(仅解答)

工作时间:白班:9:00 - 18:00

紧急问题处理

论坛响应时间:10分钟

问题处理方式:1对1处理(优先)

工作时间:白班:9:00 - 18:00

工作时间:晚班:18:00 - 24:00

立即付费处理
快速回复 返回顶部 返回列表