Improved performance of getIP.php

This commit is contained in:
adolfintel 2019-03-15 08:42:37 +01:00
parent 78c0190618
commit 7e3a1dc50e
3 changed files with 21 additions and 4 deletions

1
.gitignore vendored
View file

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

2
doc.md
View file

@ -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:

View file

@ -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"); $locFile="getIP_serverLocation.php";
$details = json_decode($json, true); $serverLoc=null;
if (array_key_exists("loc", $details)){ if(file_exists($locFile)){
$serverLoc = $details["loc"]; 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 {