diff --git a/doc.md b/doc.md index 21d73cf..367c7c5 100644 --- a/doc.md +++ b/doc.md @@ -304,10 +304,10 @@ You need to start the test with your replacements like this: w.postMessage('start {"url_dl": "newGarbageURL", "url_ul": "newEmptyURL", "url_ping": "newEmptyURL", "url_getIp": "newIpURL"}') ``` ## Telemetry -Telemetry currently requires PHP and either MySQL or SQLite. +Telemetry currently requires PHP and either MySQL, PostgreSQL or SQLite. To set up the telemetry, we need to do 4 things: -* copy `telemetry.php` -* edit `telemetry.php` to add your database settings +* copy `telemetry.php` and `telemetry_settings.php` +* edit `telemetry_settings.php` to add your database settings * create the database * enable telemetry @@ -317,8 +317,13 @@ Log into your database using phpMyAdmin or a similar software and import `teleme If you see a table called `speedtest_users`, empty, you did it right. ### Configuring `telemetry.php` -Open telemetry.php with notepad or a similar text editor. -Set your preferred database, ``$db_type="mysql";`` or ``$db_type="sqlite";`` +Open telemetry_settings.php with notepad or a similar text editor. +Set your preferred database, ``$db_type="mysql";``, ``$db_type="sqlite";`` or ``$db_type="postgresql";`` +If you choose to use Sqlite3, you must set the path to your database file: +```php +$Sqlite_db_file = "../telemetry.sql"; +``` + If you choose to use MySQL, you must also add your database credentials: ```php $MySql_username="USERNAME"; //your database username @@ -327,6 +332,14 @@ $MySql_hostname="DB_HOSTNAME"; //database address, usually localhost\ $MySql_databasename="DB_NAME"; //the name of the database where you loaded telemetry.sql ``` +If you choose to use PostgreSQL, you must also add your database credentials: +```php +$PostgreSql_username="USERNAME"; //your database username +$PostgreSql_password="PASSWORD"; //your database password +$PostgreSql_hostname="DB_HOSTNAME"; //database address, usually localhost +$PostgreSql_databasename="DB_NAME"; //the name of the database where you loaded telemetry.sql +``` + ### Enabling telemetry Edit your test page; where you start the worker, you need to specify the `telemetry_level`. There are 3 levels: diff --git a/telemetry.php b/telemetry.php index 61458f3..373f7a9 100644 --- a/telemetry.php +++ b/telemetry.php @@ -1,5 +1,5 @@ prepare("INSERT INTO speedtest_users (ip,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2"); $stmt->bind_param("ssssssss",$ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log) or die("3"); @@ -25,10 +19,7 @@ if($db_type=="mysql"){ $conn->close() or die("6"); }elseif($db_type=="sqlite"){ - - $file_db = "../telemetry.sql"; - - $conn = new PDO("sqlite:$file_db") or die("1"); + $conn = new PDO("sqlite:$Sqlite_db_file") or die("1"); $conn->exec(" CREATE TABLE IF NOT EXISTS `speedtest_users` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -46,6 +37,16 @@ if($db_type=="mysql"){ $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2"); $stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); $conn = null; - +}elseif($db_type=="postgresql"){ + // Prepare connection parameters for db connection + $conn_host = "host=$PostgreSql_hostname"; + $conn_db = "dbname=$PostgreSql_databasename"; + $conn_user = "user=$PostgreSql_username"; + $conn_password = "password=$PostgreSql_password"; + // Create db connection + $conn = new PDO("pgsql:$conn_host;$conn_db;$conn_user;$conn_password") or die("1"); + $stmt = $conn->prepare("INSERT INTO speedtest_users (ip,ua,lang,dl,ul,ping,jitter,log) VALUES (?,?,?,?,?,?,?,?)") or die("2"); + $stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); + $conn = null; } ?> diff --git a/telemetry_settings.php b/telemetry_settings.php new file mode 100644 index 0000000..8995b62 --- /dev/null +++ b/telemetry_settings.php @@ -0,0 +1,20 @@ +