diff --git a/doc.md b/doc.md index 1b08aec..5f85248 100644 --- a/doc.md +++ b/doc.md @@ -319,7 +319,7 @@ w.postMessage('start {"url_dl": "newGarbageURL", "url_ul": "newEmptyURL", "url_p Telemetry currently requires PHP and either MySQL, PostgreSQL or SQLite. To set up the telemetry, we need to do 4 things: * copy `telemetry.php` and `telemetry_settings.php` -* edit `telemetry_settings.php` to add your database settings +* edit `telemetry_settings.php` to add your database settings or the csv filename and date timezone if CSV is used instead of database storage. * create the database * enable telemetry @@ -352,6 +352,12 @@ $PostgreSql_hostname="DB_HOSTNAME"; //database address, usually localhost $PostgreSql_databasename="DB_NAME"; //the name of the database where you loaded telemetry_postgresql.sql ``` +If you choose to use CSV file, you must set the Csv_File and timezone variables. +```php +$Csv_File="myReportFile.csv"; +$timezone='Europe/Paris'; +``` + ### 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 3b19adf..ce456ec 100644 --- a/telemetry.php +++ b/telemetry.php @@ -49,4 +49,25 @@ if($db_type=="mysql"){ $stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3"); $conn = null; } +elseif($db_type=="csv"){ + // Prepare the csv formatted string + date_default_timezone_set($timezone); + $date = date('Y-m-d H:i:s'); + $str = '"' . $date . '",'; + $str .= '"' . $ip . '",'; + $str .= '"' . $ua . '",'; + $str .= '"' . $dl . '",'; + $str .= '"' . $ul . '",'; + $str .= '"' . $ping . '",'; + $str .= '"' . $jitter . '"' . "\n"; + + // Set header if this is a new file + if (!file_exists($Csv_File)) { + $header = '"date","ip","ua","download","upload","ping","jitter"' . "\n"; + file_put_contents($Csv_File, $header, FILE_APPEND); + } + + // Writting line to file + file_put_contents($Csv_File, $str, FILE_APPEND); +} ?> diff --git a/telemetry_settings.php b/telemetry_settings.php index e27098d..4bb9b62 100644 --- a/telemetry_settings.php +++ b/telemetry_settings.php @@ -1,6 +1,6 @@