Преглед изворни кода

Improved performance of getIP.php

adolfintel пре 6 година
родитељ
комит
7e3a1dc50e
3 измењених фајлова са 21 додато и 4 уклоњено
  1. 1 0
      .gitignore
  2. 2 0
      doc.md
  3. 18 4
      getIP.php

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 telemetry/idObfuscation_salt.php
 telemetry/idObfuscation_salt.php
+getIP_serverLocation.php

+ 2 - 0
doc.md

@@ -41,6 +41,8 @@ Later we'll see how to use the test without PHP, and how to configure the teleme
 
 
 __Important:__ keep all the files together; all paths are relative to the js file
 __Important:__ keep all the files together; all paths are relative to the js file
 
 
+__Important:__ Make sure PHP is allowed to write to the directory where you're installing the speedtest because getIP.php needs to create a cache file to improve performance.
+
 ## Basic usage
 ## Basic usage
 You can start using this speedtest on your site without any special knowledge.  
 You can start using this speedtest on your site without any special knowledge.  
 Start by copying one of the included examples. Here's a description for each of them:
 Start by copying one of the included examples. Here's a description for each of them:

+ 18 - 4
getIP.php

@@ -89,10 +89,24 @@ if (isset($_GET["isp"])) {
 		}
 		}
         if (isset($_GET["distance"])) {
         if (isset($_GET["distance"])) {
             if ($clientLoc) {
             if ($clientLoc) {
-                $json = file_get_contents("https://ipinfo.io/json");
-                $details = json_decode($json, true);
-                if (array_key_exists("loc", $details)){
-                    $serverLoc = $details["loc"];
+				$locFile="getIP_serverLocation.php";
+				$serverLoc=null;
+				if(file_exists($locFile)){
+					require $locFile;
+				}else{
+					$json = file_get_contents("https://ipinfo.io/json");
+					$details = json_decode($json, true);
+					if (array_key_exists("loc", $details)){
+						$serverLoc = $details["loc"];
+					}
+					if($serverLoc){
+						$lf=fopen($locFile,"w");
+						fwrite($lf,chr(60)."?php\n");
+						fwrite($lf,'$serverLoc="'.addslashes($serverLoc).'";');
+						fwrite($lf,"\n");
+						fwrite($lf,"?".chr(62));
+						fclose($lf);
+					}
 				}
 				}
                 if ($serverLoc) {
                 if ($serverLoc) {
                     try {
                     try {