瀏覽代碼

optimize report speed rate

badapple9 4 年之前
父節點
當前提交
c7391513af
共有 3 個文件被更改,包括 6 次插入2 次删除
  1. 2 0
      backend/report.php
  2. 3 1
      index.html
  3. 1 1
      results.html

+ 2 - 0
backend/report.php

@@ -19,6 +19,8 @@ $reportData = [
     "created" => date('Y-m-d H:i:s', time()),
 ];
 
+if (empty($reportData['ip'])) exit;
+
 $oldLog = $store->where('ip', '=', $reportData['ip'])->fetch();
 
 if (is_array($oldLog) && empty($oldLog)) {

+ 3 - 1
index.html

@@ -12,6 +12,7 @@
 var s=new Speedtest(); //create speedtest object
 var xhr=new XMLHttpRequest();
 var url_report='./backend/report.php';
+var milestone=0;
 s.onupdate=function(data){ //callback to update data in UI
     I("ip").textContent=data.clientIp;
     I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
@@ -25,12 +26,13 @@ s.onupdate=function(data){ //callback to update data in UI
 	var isp = ipIspArr[1];
 	var addr = ipIspArr[2] === undefined? '' :ipIspArr[2];
 	var progress = Math.floor(100*prog);
-	if (progress > 20 && (progress % 10 == 0)) {
+	if (progress > 20 && (progress % 10 == 0) && progress != milestone) {
 		var params = 'ip='+ip+'&isp='+isp+'&addr='+addr+'&dspeed='+I("dlText").textContent+'&uspeed='+I("ulText").textContent+'&ping='+I("pingText").textContent
 						+'&jitter='+I("jitText").textContent;
 		xhr.open('POST', url_report, true);
 		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 		xhr.send(params);
+		milestone = progress;
 	}
 }
 s.onend=function(aborted){ //callback for test ended/aborted

+ 1 - 1
backend/results.html → results.html

@@ -33,7 +33,7 @@
 
         table.render({
             elem: '#test'
-            ,url:'./results-api.php'
+            ,url:'./backend/results-api.php'
             ,cellMinWidth: 80
             ,cols: [[
                 {field:'ip', title: 'IP地址'}