diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 8f4f139..0000000 --- a/.editorconfig +++ /dev/null @@ -1,18 +0,0 @@ -# EditorConfig is awesome: http://EditorConfig.org - -root = true - -[*] -end_of_line = lf -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space -indent_size = 4 -charset = utf-8 - -[*.js] -indent_size = 2 -indent_style = space - -[*.md] -trim_trailing_whitespace = false diff --git a/example-gauges.html b/Frontend/example-gauges.html similarity index 53% rename from example-gauges.html rename to Frontend/example-gauges.html index 088a38f..8c3298c 100644 --- a/example-gauges.html +++ b/Frontend/example-gauges.html @@ -1,110 +1,52 @@ - - -HTML5 Speedtest - + + +HTML5 Speedtest - +

HTML5 Speedtest

-
-
-
-
-
Download
- -
-
Mbps
-
-
-
Upload
- -
-
Mbps
-
-
-
-
-
Ping
- -
-
ms
-
-
-
Jitter
- -
-
ms
-
-
-
- IP Address: -
+
+

Selecting a server...

+
+ -Source code - \ No newline at end of file diff --git a/example-telemetry-resultSharing.html b/Frontend/example-telemetry-resultSharing.html similarity index 54% rename from example-telemetry-resultSharing.html rename to Frontend/example-telemetry-resultSharing.html index 7a0e743..eee4835 100644 --- a/example-telemetry-resultSharing.html +++ b/Frontend/example-telemetry-resultSharing.html @@ -1,9 +1,179 @@ - - -HTML5 Speedtest + + - +HTML5 Speedtest - -

HTML5 Speedtest - Telemetry and sharing example

-
-
-
-
-
Download
- -
-
Mbps
-
-
-
Upload
- -
-
Mbps
-
-
-
-
-
Ping
- -
-
ms
-
-
-
Jitter
- -
-
ms
-
-
-
- IP Address: -
- + +

HTML5 Speedtest

+
+

Selecting a server...

+
+ -
Basic telemetry is active; results will be saved in your database, without the full log. If the results don't appear, or the sharing panel doesn't appear at the end of the test, check the settings in telemetry_settings.php
-Source code - \ No newline at end of file diff --git a/results/OpenSans-Light.ttf b/Frontend/results/OpenSans-Light.ttf similarity index 100% rename from results/OpenSans-Light.ttf rename to Frontend/results/OpenSans-Light.ttf diff --git a/results/OpenSans-Semibold.ttf b/Frontend/results/OpenSans-Semibold.ttf similarity index 100% rename from results/OpenSans-Semibold.ttf rename to Frontend/results/OpenSans-Semibold.ttf diff --git a/results/index.php b/Frontend/results/index.php similarity index 100% rename from results/index.php rename to Frontend/results/index.php diff --git a/Frontend/server_selector.js b/Frontend/server_selector.js new file mode 100644 index 0000000..f27be8b --- /dev/null +++ b/Frontend/server_selector.js @@ -0,0 +1,106 @@ +/* + HTML5 Speedtest v4.6.1 MPOT - Server selector + by Federico Dossena + https://github.com/adolfintel/speedtest/ + GNU LGPLv3 License +*/ + +//pings the specified URL, then calls the function result. Result will receive a parameter which is either the time it took to ping the URL, or -1 if something went wrong. +//var PING_TIMEOUT=500; //disabled because it breaks IE11 +function ping(url,result){ + var xhr=new XMLHttpRequest(); + var t=new Date().getTime(); + xhr.onload=function(){ + if(xhr.responseText.length==0){ //we expect an empty response + var instspd=new Date().getTime()-t; //rough timing estimate + try{ + //try to get more accurate timing using performance API + var p=performance.getEntries(); + p=p[p.length-1]; + var d=p.responseStart-p.requestStart; + if(d<=0) d=p.duration; + if(d>0&&d=0){ + if(t 1000 * settings.time_ulGraceTime){ - if (totLoaded > 0){ // if the connection is so slow that we didn't get a single chunk yet, do not reset - startT = new Date().getTime() - totLoaded = 0.0; - } - graceTimeDone = true; - } - }else{ - var speed = totLoaded / (t / 1000.0) - ulStatus = ((speed * 8 * settings.overheadCompensationFactor)/(settings.useMebibits?1048576:1000000)).toFixed(2) // speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 or 1000000 to go to megabits/mebibits - if (((t / 1000.0) > settings.time_ul && ulStatus > 0) || failed) { // test is over, stop streams and timer - if (failed || isNaN(ulStatus)) ulStatus = 'Fail' - clearRequests() - clearInterval(interval) - ulProgress = 1 - tlog('ulTest finished '+ulStatus) - done() - } - } - }.bind(this), 200) + var testFunction=function(){ + var totLoaded = 0.0, // total number of transmitted bytes + startT = new Date().getTime(), // timestamp when test was started + graceTimeDone = false, //set to true after the grace time is past + failed = false // set to true if a stream fails + xhr = [] + // function to create an upload stream. streams are slightly delayed so that they will not end at the same time + var testStream = function (i, delay) { + setTimeout(function () { + if (testStatus !== 3) return // delayed stream ended up starting after the end of the upload test + tlog('ul test stream started '+i+' '+delay) + var prevLoaded = 0 // number of bytes transmitted last time onprogress was called + var x = new XMLHttpRequest() + xhr[i] = x + var ie11workaround + if (settings.forceIE11Workaround) ie11workaround = true; else { + try { + xhr[i].upload.onprogress + ie11workaround = false + } catch (e) { + ie11workaround = true + } + } + if (ie11workaround) { + // IE11 workarond: xhr.upload does not work properly, therefore we send a bunch of small 256k requests and use the onload event as progress. This is not precise, especially on fast connections + xhr[i].onload = function () { + tlog('ul stream progress event (ie11wa)') + totLoaded += reqsmall.size; + testStream(i, 0) + } + xhr[i].onerror = function () { + // error, abort + tlog('ul stream failed (ie11wa)') + if (settings.xhr_ignoreErrors === 0) failed = true //abort + try { xhr[i].abort() } catch (e) { } + delete (xhr[i]) + if (settings.xhr_ignoreErrors === 1) testStream(i,0); //restart stream + } + xhr[i].open('POST', settings.url_ul + url_sep(settings.url_ul) + 'r=' + Math.random(), true) // random string to prevent caching + xhr[i].setRequestHeader('Content-Encoding', 'identity') // disable compression (some browsers may refuse it, but data is incompressible anyway) + xhr[i].send(reqsmall) + } else { + // REGULAR version, no workaround + xhr[i].upload.onprogress = function (event) { + tlog('ul stream progress event '+i+' '+event.loaded) + if (testStatus !== 3) { try { x.abort() } catch (e) { } } // just in case this XHR is still running after the upload test + // progress event, add number of new loaded bytes to totLoaded + var loadDiff = event.loaded <= 0 ? 0 : (event.loaded - prevLoaded) + if (isNaN(loadDiff) || !isFinite(loadDiff) || loadDiff < 0) return // just in case + totLoaded += loadDiff + prevLoaded = event.loaded + }.bind(this) + xhr[i].upload.onload = function () { + // this stream sent all the garbage data, start again + tlog('ul stream finished '+i) + testStream(i, 0) + }.bind(this) + xhr[i].upload.onerror = function () { + tlog('ul stream failed '+i) + if (settings.xhr_ignoreErrors === 0) failed=true //abort + try { xhr[i].abort() } catch (e) { } + delete (xhr[i]) + if (settings.xhr_ignoreErrors === 1) testStream(i, 0) //restart stream + }.bind(this) + // send xhr + xhr[i].open('POST', settings.url_ul + url_sep(settings.url_ul) + 'r=' + Math.random(), true) // random string to prevent caching + xhr[i].setRequestHeader('Content-Encoding', 'identity') // disable compression (some browsers may refuse it, but data is incompressible anyway) + xhr[i].send(req) + } + }.bind(this), 1) + }.bind(this) + // open streams + for (var i = 0; i < settings.xhr_ulMultistream; i++) { + testStream(i, settings.xhr_multistreamDelay * i) + } + // every 200ms, update ulStatus + interval = setInterval(function () { + tlog('UL: '+ulStatus+(graceTimeDone?'':' (in grace time)')) + var t = new Date().getTime() - startT + if (graceTimeDone) ulProgress = t / (settings.time_ul * 1000) + if (t < 200) return + if (!graceTimeDone){ + if (t > 1000 * settings.time_ulGraceTime){ + if (totLoaded > 0){ // if the connection is so slow that we didn't get a single chunk yet, do not reset + startT = new Date().getTime() + totLoaded = 0.0; + } + graceTimeDone = true; + } + }else{ + var speed = totLoaded / (t / 1000.0) + ulStatus = ((speed * 8 * settings.overheadCompensationFactor)/(settings.useMebibits?1048576:1000000)).toFixed(2) // speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 or 1000000 to go to megabits/mebibits + if (((t / 1000.0) > settings.time_ul && ulStatus > 0) || failed) { // test is over, stop streams and timer + if (failed || isNaN(ulStatus)) ulStatus = 'Fail' + clearRequests() + clearInterval(interval) + ulProgress = 1 + tlog('ulTest finished '+ulStatus) + done() + } + } + }.bind(this), 200) + }.bind(this); + if(settings.xhr_ul_sendPostRequestBeforeStartingTest){ + tlog('Sending POST request before performing upload test'); + xhr=[]; + xhr[0]=new XMLHttpRequest(); + xhr[0].onload=xhr[0].onerror=function(){ + tlog('POST request sent, starting upload test'); + testFunction(); + }.bind(this); + xhr[0].open('POST',settings.url_ul); + xhr[0].send(); + }else testFunction(); } // ping+jitter test, function done is called when it's over var ptCalled = false // used to prevent multiple accidental calls to pingTest diff --git a/telemetry/stats.php b/Frontend/telemetry/stats.php similarity index 100% rename from telemetry/stats.php rename to Frontend/telemetry/stats.php diff --git a/telemetry/telemetry.php b/Frontend/telemetry/telemetry.php similarity index 100% rename from telemetry/telemetry.php rename to Frontend/telemetry/telemetry.php diff --git a/telemetry/telemetry_mysql.sql b/Frontend/telemetry/telemetry_mysql.sql similarity index 100% rename from telemetry/telemetry_mysql.sql rename to Frontend/telemetry/telemetry_mysql.sql diff --git a/telemetry/telemetry_postgresql.sql b/Frontend/telemetry/telemetry_postgresql.sql similarity index 100% rename from telemetry/telemetry_postgresql.sql rename to Frontend/telemetry/telemetry_postgresql.sql diff --git a/telemetry/telemetry_settings.php b/Frontend/telemetry/telemetry_settings.php similarity index 100% rename from telemetry/telemetry_settings.php rename to Frontend/telemetry/telemetry_settings.php diff --git a/README.md b/README.md index 50018b5..6712e79 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,16 @@ -# HTML5 Speedtest +# HTML5 Speedtest - Multiple Points of Test -No Flash, No Java, No Websocket, No Bullshit. +__Work in progress!__ -This is a very lightweight Speedtest implemented in Javascript, using XMLHttpRequest and Web Workers. +This branch isn't stable yet, don't use it in production. +Documentation isn't done yet. -## Try it -[Take a Speedtest](http://speedtest.fdossena.com) +## Multiple Points of Test +This branch allows usage of multiple test servers instead of just 1. The client runs a server selector, which pings a list of test servers and chooses the one with the best ping. -## Compatibility -Only modern browsers are supported (IE11, latest Edge, latest Chrome, latest Firefox, latest Safari) +## Frontend server +This is the server that hosts the UI, the JS files, and optionally the telemetry -## Features -* Download -* Upload -* Ping -* Jitter -* IP Address -* Telemetry (optional) -* Results sharing (optional) +## Test backends +These are the servers to which the clients can connect and actually do the test. They don't host the UI, only the PHP files required for the test. -![Screenshot](https://speedtest.fdossena.com/screenshot.png) - - -## Requirements - - A reasonably fast web server with PHP (see doc.md for details and use without PHP) - - Your server must accept large POST requests (up to 20 Megabytes), otherwise the upload test will fail - - It's also better if your server does not use compression, but it's not mandatory - -## Quick installation videos -* [Debian 9.0 with Apache](https://fdossena.com/?p=speedtest/quickstart_deb.frag) -* [Windows Server 2016 with IIS](https://fdossena.com/?p=speedtest/quickstart_win.frag) -* [Ubuntu (External)](https://freedif.org/how-to-install-selfhosted-speedtest) - -Also, here's an [example config on Ubuntu 16 LTS](https://github.com/adolfintel/speedtest/issues/50) - -## How to use in your site -* See the examples -* [Read the wiki](https://github.com/adolfintel/speedtest/wiki) -* Read doc.md - -## Docker -Please see the ```docker``` branch - -## Node.js backend -A Node.js implementation is available in the ```node``` branch, maintained by [dunklesToast](https://github.com/dunklesToast). - -## Donate -[![Donate with Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/fdossena/donate) -[Donate with PayPal](https://www.paypal.me/sineisochronic) -Send ETH at this address: ```0x8A5273d4e2618c4cff2C62d8EB731701FceEd8E3``` - -## License -Copyright (C) 2016-2018 Federico Dossena - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this program. If not, see . diff --git a/empty.php b/Test backends/empty.php similarity index 59% rename from empty.php rename to Test backends/empty.php index eb1fc85..3229254 100644 --- a/empty.php +++ b/Test backends/empty.php @@ -4,4 +4,7 @@ header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Connection: keep-alive"); +header('Access-Control-Allow-Origin: *'); +header('Access-Control-Allow-Methods: GET, POST'); +header('Access-Control-Allow-Headers: Content-Encoding'); ?> \ No newline at end of file diff --git a/garbage.php b/Test backends/garbage.php similarity index 90% rename from garbage.php rename to Test backends/garbage.php index 27c1bfc..08d9b02 100644 --- a/garbage.php +++ b/Test backends/garbage.php @@ -5,6 +5,8 @@ @ini_set('output_handler', ''); // Headers header('HTTP/1.1 200 OK'); +header('Access-Control-Allow-Origin: *'); +header('Access-Control-Allow-Methods: GET, POST'); // Download follows... header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); diff --git a/getIP.php b/Test backends/getIP.php similarity index 97% rename from getIP.php rename to Test backends/getIP.php index e30cde3..77465c3 100644 --- a/getIP.php +++ b/Test backends/getIP.php @@ -6,6 +6,8 @@ */ $ip = ""; header('Content-Type: application/json; charset=utf-8'); +header('Access-Control-Allow-Origin: *'); +header('Access-Control-Allow-Methods: GET, POST'); if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['X-Real-IP'])) { diff --git a/doc.md b/doc.md deleted file mode 100644 index 396bc80..0000000 --- a/doc.md +++ /dev/null @@ -1,445 +0,0 @@ -# HTML5 Speedtest - -> by Federico Dossena -> Version 4.6.1, August 8, 2018 -> [https://github.com/adolfintel/speedtest/](https://github.com/adolfintel/speedtest/) - - -## Introduction -In this document, we will introduce an XHR based HTML5 Speedtest and see how to use it. -This test measures download speed, upload speed, ping and jitter. - -First of all, the requirements to run this test: - -* The browser have to support XHR Level 2 and Web Workers and Javascript must be enabled. - * Internet Explorer 11 - * Microsoft Edge 12+ - * Mozilla Firefox 12+ - * Google Chrome / Chromium 31+ - * Apple Safari 7.1+ - * Opera 18+ -* Client side, the test can use up to 500 megabytes of RAM -* Server side, you'll need a fast connection (at least 100 Mbps recommended), and the web server must accept large POST requests (up to 20 megabytes). - The recommended setup is: GNU/Linux, Apache2, PHP, MySQL database (if you want to use telemetry). - -If this looks good, let's proceed and see how to use the test. - -## Quick installation videos -* [Debian 9.0 with Apache](https://fdossena.com/?p=speedtest/quickstart_deb.frag) -* [Windows Server 2016 with IIS](https://fdossena.com/?p=speedtest/quickstart_win.frag) - -## Installation -To install the test on your server, upload the following files: - -* `speedtest_worker.min.js` -* `garbage.php` -* `getIP.php` -* `empty.php` -* one of the examples - -Later we'll see how to use the test without PHP, and how to configure the telemetry and result sharing if you want to use that. - -__Important:__ keep all the files together; all paths are relative to the js file - -## Basic usage -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: -* `example-basic.html`: This example shows the most basic configuration possible. Everything runs with the default settings, in a very simple page where the output is shown -* `example-pretty.html`: This is a more sophisticated example, with a nicer layout and a start/stop button. __This is the best starting point for most users__ -* `example-progressBar.html`: A modified version of `example-pretty.html` with a progress indicator -* `example-customSettings.html`: A modified version of `example-pretty.html` showing how the test can be started with custom parameters -* `example-customSettings2.html`: A modified version of `example-pretty.html` showing how to make a custom test with only download and upload -* `example-gauges.html`: The most sophisticated example, with the same functions as `example-pretty.html` but also gauges and progress indicators for each test. This is the nicest example included, and also a good starting point, but drawing the gauges may slow down the test on slow devices like a Raspberry Pi -* `example-chart.html`: The old example5.html, showing how to use the test with the Chart.js library - -These 2 examples require some additional server configuration, discussed in the Telemetry section: -* `example-telemetry.html`: A modified version of `example-pretty.html` with basic telemetry turned on. See the section on Telemetry for details -* `example-telemetry-resultsSharing.html`: A modified version of `example-telemetry.html` with results sharing. This is the most complete and most complex example, showing off all of the speedtest features - -### Customizing your example -The included examples are good starting places if you want to have a simple speedtest on your site. -Once you've tested everything and you're sure that everything works, edit it and add some custom stuff like your logo or new colors. -If you want to change the test parameters, for instance to make the download test shorter, you can do so in every example: -Look for the line that contains `postMessage('start ` -This is where custom parameters can be passed to the test as a JSON string. You can write the string manually or use ``JSON.stringify`` to do that for you. -Here's an example: -```js -w.postMessage('start {"time_dl":"10"}'); -``` -This starts the test with default settings, but sets the download test to last only 10 seconds. -Here's a cleaner version using ``JSON.stringify``: -```js -var params={ - time_dl:10 -} -w.postMessage('start '+JSON.stringify(params)) -``` -Notice that there is a space after the word `start`, don't forget that! - -For a list of all test settings, look below, under Test parameters and Advanced test parameters. __Do not change anything if you don't know what you're doing.__ - -## Advanced usage -If you don't want to start from one of the examples, here's how to use the worker. Examples are still good for reference, so keep them handy. - -To run the test, you need to do 3 things: - -* Create the worker -* Write some code that handles the data coming from the worker -* Start the test - -### Creating the worker -```js -var w = new Worker("speedtest_worker.min.js") -``` - -__Important:__ use the minified version, it's smaller! - -### Response handler -First, we set up a timer that fetches the status of the worker continuously: -```js -var timer = setInterval(function () { - w.postMessage('status') -}, 100) -``` - -Then we write a response handler that receives the status and updates the page. Later -we'll see the details of the format of the response. - -```js -w.onmessage = function (event) { - var data = JSON.parse(event.data); - if (data.testState >= 4) { - clearInterval(timer) // test is finished or aborted - } - // .. update your page here .. -} -``` - -#### Response format -The response from the worker is a JSON string containing these entries: - -* __testState__: an integer between -1 and 5 - * `-1` = Test not started yet - * `0` = Test starting - * `1` = Download test in progress - * `2` = Ping + Jitter test in progress - * `3` = Upload test in progress - * `4` = Test finished - * `5` = Test aborted -* __dlStatus__: either - * Empty string (not started or aborted) - * Download speed in Megabit/s as a number with 2 decimals - * The string "Fail" (test failed) -* __ulStatus__: either - * Empty string (not started or aborted) - * Upload speed in Megabit/s as a number with 2 decimals - * The string "Fail" (test failed) -* __pingStatus__: either - * Empty string (not started or aborted) - * Estimated ping in milliseconds as a number with 2 decimals - * The string "Fail" (test failed) -* __clientIp__: either - * Empty string (not fetched yet or failed) - * The client's IP address as a string (with ISP info if enabled) -* __jitterStatus__: either - * Empty string (not started or aborted) - * Estimated jitter in milliseconds as a number with 2 decimals (lower = stable connection) - * The string "Fail" (test failed) -* __dlProgress__: the progress of the download test as a number between 0 and 1 -* __ulProgress__: the progress of the upload test as a number between 0 and 1 -* __pingProgress__: the progress of the ping+jitter test as a number between 0 and 1 -* __testId__: when telemetry is active, this is the ID of the test as an integer. This string is 'noID' until the test is finished (testState 4). This ID is used for results sharing - -Note: clientIp appears before jitterStatus. This is not a mistake, it's to keep the js file compatible with older pages from before the jitter test was introduced. - -### Starting the test -To start the test with the default settings, which is usually the best choice, send the start command to the worker: - -```js -w.postMessage('start') -``` - -If you want, you can change these settings and pass them to the worker as JSON when you start it, like this: - -```js -w.postMessage('start {"param1": "value1", "param2": "value2", ...}') -``` -or this: -```js -var params{ - param1:value1, - param2:value2, - ... -} -w.postMessage('start '+JSON.stringify(params)) -``` - -#### Test parameters -* __time_dl__: How long the download test should be in seconds. The test will continue regardless of this limit if the speed is still 0.00 when the limit is reached. - * Default: `15` - * Recommended: `>=5` -* __time_ul__: How long the upload test should be in seconds. The test will continue regardless of this limit if the speed is still 0.00 when the limit is reached. - * Default: `15` - * Recommended: `>=10` -* __count_ping__: How many pings to perform in the ping test - * Default: `35` - * Recommended: `>=20` -* __url_dl__: path to garbage.php or a large file to use for the download test. - * Default: `garbage.php` - * __Important:__ path is relative to js file -* __url_ul__: path to an empty file or empty.php to use for the upload test - * Default: `empty.php` - * __Important:__ path is relative to js file -* __url_ping__: path to an empty file or empty.php to use for the ping test - * Default: `empty.php` - * __Important:__ path is relative to js file -* __url_getIp__: path to getIP.php or replacement - * Default: `getIP.php` - * __Important:__ path is relative to js file -* __url_telemetry__: path to telemetry.php or replacement - * Default: `telemetry/telemetry.php` - * __Important:__ path is relative to js file - * __Note:__ you can ignore this parameter if you're not using the telemetry - -#### Advanced test parameters -* __test_order__: the order in which tests will be performed. Each character represents an operation: - * `I`: get IP - * `D`: download test - * `U`: upload test - * `P`: ping + jitter test - * `_`: delay 1 second - * Default test order: `IP_D_U` - * __Important:__ Tests can only be run once - * __Important:__ On Firefox, it is better to run the upload test last -* __getIp_ispInfo__: if true, the server will try to get ISP info and pass it along with the IP address. This will add `isp=true` to the request to `url_getIp`. getIP.php accomplishes this using ipinfo.io - * Default: `true` -* __getIp_ispInfo_distance__: if true, the server will try to get an estimate of the distance from the client to the speedtest server. This will add a `distance` argument to the request to `url_getIp`. `__getIp_ispInfo__` must be enabled in order for this to work. getIP.php accomplishes this using ipinfo.io - * `km`: estimate distance in kilometers - * `mi`: estimate distance in miles - * not set: do not measure distance - * Default: `km` -* __enable_quirks__: enables browser-specific optimizations. These optimizations override some of the default settings. They do not override settings that are explicitly set. - * Default: `true` -* __garbagePhp_chunkSize__: size of chunks sent by garbage.php in megabytes - * Default: `20` - * Recommended: `>=10` - * Maximum: `100` -* __xhr_dlMultistream__: how many streams should be opened for the download test - * Default: `10` - * Recommended: `>=3` - * Default override: 3 on Edge if enable_quirks is true - * Default override: 5 on Chromium-based if enable_quirks is true -* __xhr_ulMultistream__: how many streams should be opened for the upload test - * Default: `3` - * Recommended: `>=1` - * Default override: 1 on Firefox if enable_quirks is true -* __xhr_ul_blob_megabytes__: size in megabytes of the blobs sent during the upload test - * Default: `20` - * Default override: 4 on Chromium-based mobile browsers (limitation introduced around version 65). This will be forced - * Default override: IE11 and Edge currently use a different method for the upload test. This parameter is ignored -* __xhr_multistreamDelay__: how long should the multiple streams be delayed (in ms) - * Default: `300` - * Recommended: `>=100`, `<=700` -* __xhr_ignoreErrors__: how to react to errors in download/upload streams and the ping test - * `0`: Fail test on error (behaviour of previous versions of this test) - * `1`: Restart a stream/ping when it fails - * `2`: Ignore all errors - * Default: `1` - * Recommended: `1` -* __time_dlGraceTime__: How long to wait (in seconds) before actually measuring the download speed. This is a good idea because we want to wait for the TCP window to be at its maximum (or close to it) - * Default: `1.5` - * Recommended: `>=0` -* __time_ulGraceTime__: How long to wait (in seconds) before actually measuring the upload speed. This is a good idea because we want to wait for the buffers to be full (avoids the peak at the beginning of the test) - * Default: `3` - * Recommended: `>=1` -* __ping_allowPerformanceApi__: toggles use of Performance API to improve accuracy of Ping/Jitter test on browsers that support it. - * Default: `true` -* __useMebibits__: use mebibits/s instead of megabits/s for the speeds - * Default: `false` -* __overheadCompensationFactor__: compensation for HTTP and network overhead. Default value assumes typical MTUs used over the Internet. You might want to change this if you're using this in your internal network with different MTUs, or if you're using IPv6 instead of IPv4. - * Default: `1.06` probably a decent estimate for all overhead. This was measured empirically by comparing the measured speed and the speed reported by my the network adapter. - * `1048576/925000`: old default value. This is probably too high. - * `1.0513`: HTTP+TCP+IPv6+ETH, over the Internet (empirically tested, not calculated) - * `1.0369`: Alternative value for HTTP+TCP+IPv4+ETH, over the Internet (empirically tested, not calculated) - * `1.081`: Yet another alternative value for over the Internet (empirically tested, not calculated) - * `1514 / 1460`: TCP+IPv4+ETH, ignoring HTTP overhead - * `1514 / 1440`: TCP+IPv6+ETH, ignoring HTTP overhead - * `1`: ignore overheads. This measures the speed at which you actually download and upload files rather than the raw connection speed -* __telemetry_level__: The type of telemetry to use. See the telemetry section for more info about this - * Default: `none` - * `basic`: send results only - * `full`: send results and debug info -* __telemetry_extra__: Extra data that you want to be passed to the telemetry. This is a string field, if you want to pass an object, make sure you use ``JSON.stringify``. This string will be added to the database entry for this test. - -### Aborting the test prematurely -The test can be aborted at any time by sending an abort command to the worker: - -```js -w.postMessage('abort') -``` - -This will terminate all network activity and stop the worker. - -__Important:__ do not simply kill the worker while it's running, as it may leave pending XHR requests! - -### Important notice on backwards compatibility -__Do NOT link the js file from github or fdossena.com directly into your html file. __ - -A lot of web developers think that referring to the latest version of a library in their project is a good thing. It is not. -Things may change and I don't want to break your project, so do yourself a favor, and keep all files on your server. -You have been warned. - -## Using the test without PHP -If your server does not support PHP, or you're using something newer like Node.js, you can still use this test by replacing `garbage.php`, `empty.php` and `getIP.php` with equivalents. - -### Replacements - -#### Replacement for `garbage.php` -A replacement for `garbage.php` must generate incompressible garbage data. - -A large file (10-100 Mbytes) is a possible replacement. You can get [one here](http://downloads.fdossena.com/geth.php?r=speedtest-bigfile). - -If you're using Node.js or some other server, your replacement should accept the `ckSize` parameter (via GET) which tells it how many megabytes of garbage to generate. -It is important here to turn off compression, and generate incompressible data. -A symlink to `/dev/urandom` is also ok. - -#### Replacement for `empty.php` -Your replacement must simply respond with a HTTP code 200 and send nothing else. You may want to send additional headers to disable caching. The test assumes that Connection:keep-alive is sent by the server. -An empty file can be used for this. - -#### Replacement for `getIP.php` -Your replacement can simply respond with the client's IP as plaintext or do something more fancy. -If you want, you can also accept the `isp=true` parameter and also include the ISP info. In this case, return a JSON string containing a string called `processedString` with the text that you want to be displayed in the IP address field, and an object called `rawIspInfo` containing whatever you want (will be included in telemetry if enabled). - -#### JS -You need to start the test with your replacements like this: - -```js -w.postMessage('start {"url_dl": "newGarbageURL", "url_ul": "newEmptyURL", "url_ping": "newEmptyURL", "url_getIp": "newIpURL"}') -``` -## Telemetry -Telemetry currently requires PHP and either MySQL, PostgreSQL or SQLite. -To set up the telemetry, we need to do 4 things: -* copy the `telemetry` folder -* edit `telemetry_settings.php` to add your database settings -* create the database -* enable telemetry - -### Creating the database -This step is only for MySQL and PostgreSQL. -Log into your database using phpMyAdmin or a similar software and import the appropriate sql file into an empty database. For MySQL databases use `telemetry_mysql.sql` and for PostgreSQL databases use `telemetry_postgesql.sql`. They're inside the `telemetry` folder. You can delete the files afterwards. -If you see a table called `speedtest_users`, empty, you did it right. - -### Configuring `telemetry.php` -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 -$MySql_password="PASSWORD"; //your database password -$MySql_hostname="DB_HOSTNAME"; //database address, usually localhost -$MySql_databasename="DB_NAME"; //the name of the database where you loaded telemetry_mysql.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_postgresql.sql -``` - -### Enabling telemetry -Edit your test page; where you start the worker, you need to specify the `telemetry_level`. -There are 3 levels: -* `none`: telemetry is disabled (default) -* `basic`: telemetry collects IP, ISP info, User Agent, Preferred language, Test results -* `full`: same as above, but also collects a debug log (10-150 Kb each, not recommended unless you're developing the speedtest) - -Example: -```js -w.postMessage('start {"telemetry_level":"basic"}') -``` - -You can use example-telemetryEnabled.html and example-telemetry-resultSharing.html as starting points. - -### Results sharing -This feature generates an image that can be share by the user containing the download, upload, ping, jitter and ISP (if enabled). - -To use this feature, copy the `results` folder. You can customize the style of the generated image by editing the settings in `results/index.php`. - -This feature requires Telemetry to be enabled, and FreeType2 must be installed in PHP (if not already be installed by your distro). - -__Important:__ This feature relies on PHP functions `imagefttext` and `imageftbbox` that are well known for being problematic. The most common problem is that they can't find the font files and therefore nothing is drawn. This problem is metioned [here](http://php.net/manual/en/function.imagefttext.php) and was experienced by a lot of users. - -### Seeing the results -A basic front-end for visualizing and searching tests by ID is available in `telemetry/stats.php`. - -A login is required to access the interface. __Important__: change the default password in `telemetry_settings.php`. - -## Troubleshooting -These are the most common issues reported by users, and how to fix them. If you still need help, contact me at [info@fdossena.com](mailto:info@fdossena.com). - -#### Download test gives very low result -Are garbage.php and empty.php (or your replacements) reachable? -Press F12, select network and start the test. Do you see errors? (cancelled requests are not errors) -If a small download starts, open it in a text editor. Does it say it's missing openssl_random_pseudo_bytes()? In this case, install OpenSSL (this is usually included when you install Apache and PHP on most distros). - -#### Upload test is inaccurate, and/or I see lag spikes -Check your server's maximum POST size, make sure it's at least 20Mbytes, possibly more - -#### Download and/or upload results are slightly too optimistic -The test was fine tuned to run over a typical IPv4 internet connection. If you're using it under different conditions, see the ``overheadCompensationFactor`` parameter. - -#### All tests are wrong, give extremely high results, browser lags/crashes, ... -You're running the test on localhost, therefore it is trying to measure the speed of your loopback interface. The test is meant to be run over an Internet connection, from a different machine. - -#### Ping test shows double the actual ping -Make sure your server is sending the ```Connection:keep-alive``` header - -#### The server is behind a load balancer, proxy, etc. and I get the wrong IP address -Edit getIP.php and replace lines 5-13 with what is more appropriate in your scenario. -Example: ```$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];``` - -#### The results sharing just generates a blank image -If the image doesn't display and the browser displays a broken image icon, FreeType2 is not installed or configured properly. -If the image is blank, this usually happens because PHP can't find the font files inside the `results` folder. You can fix your PHP config or edit `results/index.php` and use absolute paths for the fonts. This is a [known issue with PHP](http://php.net/manual/en/function.imagefttext.php) and no real solution is known. - -## Known bugs and limitations -### General -* The ping/jitter test is measured by seeing how long it takes for an empty XHR to complete. It is not an acutal ICMP ping. Different browsers may also show different results, especially on very fast connections on slow devices. -### IE-Specific -* The upload test is not precise on very fast connections with high latency (will probably be fixed by Edge 17) -* On IE11, a same origin policy error is erroneously triggered under unknown conditions. Seems to be related to running the test from unusual URLs like a top level domain (for instance http://abc/speedtest). These are bugs in IE11's implementation of the same origin policy, not in the speedtest itself. -* On IE11, under unknown circumstances, on some systems the test can only be run once, after which speedtest_worker.js will not be loaded by IE until the browser is restarted. This is a rare bug in IE11. -### Firefox-Specific -* On some Linux systems with hardware acceleration turned off, the page rendering makes the browser lag, reducing the accuracy of the ping/jitter test, and potentially even the download and upload tests on very fast connections. - -## Making changes -Since this is an open source project, you can modify it. - -To make changes to the speedtest itself, edit `speedtest_worker.js` - -To create the minified version, use [UglifyJS](https://github.com/mishoo/UglifyJS2) like this: - -``` -uglifyjs -c -o speedtest_worker.min.js -- speedtest_worker.js -``` - -Pull requests are very appreciated. If you don't use github (or git), simply contact me at [info@fdossena.com](mailto:info@fdossena.com). - -__Important:__ please add your name to modified versions to distinguish them from the main project. - - -## License -This software is under the GNU LGPL license, Version 3 or newer. - -To put it short: you are free to use, study, modify, and redistribute this software and modified versions of it, for free or for money. -You can also use it in proprietary software but all changes to this software must remain under the same GNU LGPL license. - -Contact me at [info@fdossena.com](mailto:info@fdossena.com) for other licensing models. diff --git a/example-basic.html b/example-basic.html deleted file mode 100644 index b700c0f..0000000 --- a/example-basic.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - HTML5 Speedtest - - - -

HTML5 Speedtest

- -

IP Address

-

- -

Download

-

- -

Upload

-

- -

Latency

-

- - - - Source code - - - diff --git a/example-chart.html b/example-chart.html deleted file mode 100644 index d7b0ce6..0000000 --- a/example-chart.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - HTML5 Speedtest - - - - - - -

HTML Speedtest - Chart.js example

- - Run speedtest -

Charts by Chart.js

Source code - - diff --git a/example-customSettings.html b/example-customSettings.html deleted file mode 100644 index f2efa85..0000000 --- a/example-customSettings.html +++ /dev/null @@ -1,200 +0,0 @@ - - - - - -HTML5 Speedtest - - - - -

HTML5 Speedtest - Custom settings example

-
-
-
-
-
Download
-
-
Mbps
-
-
-
Upload
-
-
Mbps
-
-
-
-
-
Ping
-
-
ms
-
-
-
Jitter
-
-
ms
-
-
-
- IP Address: -
-
-
Custom parameters:
-Source code - - - \ No newline at end of file diff --git a/example-customSettings2.html b/example-customSettings2.html deleted file mode 100644 index cdcc538..0000000 --- a/example-customSettings2.html +++ /dev/null @@ -1,172 +0,0 @@ - - - - - -HTML5 Speedtest - - - - -

HTML5 Speedtest - Custom settings example

-
-
-
-
-
Download
-
-
Mbps
-
-
-
Upload
-
-
Mbps
-
-
-
-Source code - - - \ No newline at end of file diff --git a/example-pretty.html b/example-pretty.html deleted file mode 100644 index f715f43..0000000 --- a/example-pretty.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - -HTML5 Speedtest - - - - -

HTML5 Speedtest

-
-
-
-
-
Download
-
-
Mbps
-
-
-
Upload
-
-
Mbps
-
-
-
-
-
Ping
-
-
ms
-
-
-
Jitter
-
-
ms
-
-
-
- IP Address: -
-
-Source code - - - \ No newline at end of file diff --git a/example-progressBar.html b/example-progressBar.html deleted file mode 100644 index 6e0f53a..0000000 --- a/example-progressBar.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - - -HTML5 Speedtest - - - - -

HTML5 Speedtest

-
-
-
-
-
-
Download
-
-
Mbps
-
-
-
Upload
-
-
Mbps
-
-
-
-
-
Ping
-
-
ms
-
-
-
Jitter
-
-
ms
-
-
-
- IP Address: -
-
-Source code - - - \ No newline at end of file diff --git a/example-telemetryEnabled.html b/example-telemetryEnabled.html deleted file mode 100644 index 53eb53b..0000000 --- a/example-telemetryEnabled.html +++ /dev/null @@ -1,194 +0,0 @@ - - - - - -HTML5 Speedtest - - - - -

HTML5 Speedtest - Telemetry example

-
-
-
-
-
Download
-
-
Mbps
-
-
-
Upload
-
-
Mbps
-
-
-
-
-
Ping
-
-
ms
-
-
-
Jitter
-
-
ms
-
-
-
- IP Address: -
-
-
Basic telemetry is active; results will be saved in your database, without the full log. If the results don't appear, check the settings in telemetry_settings.php
-Source code - - - \ No newline at end of file diff --git a/speedtest_worker.min.js b/speedtest_worker.min.js deleted file mode 100644 index 79ba9aa..0000000 --- a/speedtest_worker.min.js +++ /dev/null @@ -1 +0,0 @@ -var testStatus=-1,dlStatus="",ulStatus="",pingStatus="",jitterStatus="",clientIp="",dlProgress=0,ulProgress=0,pingProgress=0,testId="noID",log="";function tlog(s){log+=Date.now()+": "+s+"\n"}function twarn(s){log+=Date.now()+" WARN: "+s+"\n",console.warn(s)}var settings={test_order:"IP_D_U",time_ul:15,time_dl:15,time_ulGraceTime:3,time_dlGraceTime:1.5,count_ping:35,url_dl:"garbage.php",url_ul:"empty.php",url_ping:"empty.php",url_getIp:"getIP.php",getIp_ispInfo:!0,getIp_ispInfo_distance:"km",xhr_dlMultistream:10,xhr_ulMultistream:3,xhr_multistreamDelay:300,xhr_ignoreErrors:1,xhr_dlUseBlob:!1,xhr_ul_blob_megabytes:20,garbagePhp_chunkSize:20,enable_quirks:!0,ping_allowPerformanceApi:!0,overheadCompensationFactor:1.06,useMebibits:!1,telemetry_level:0,url_telemetry:"telemetry/telemetry.php",telemetry_extra:""},xhr=null,interval=null,test_pointer=0;function url_sep(url){return url.match(/\?/)?"&":"?"}function clearRequests(){if(tlog("stopping pending XHRs"),xhr){for(var i=0;i=settings.test_order.length)0settings.time_dl&&01e3*settings.time_dlGraceTime&&(0settings.time_ul&&01e3*settings.time_ulGraceTime&&(0