Skip to content

Multiple test points (PHP)

Federico Dossena edited this page Mar 9, 2020 · 3 revisions

The speedtest can automatically choose between multiple test points and use the one with the lowest ping in a list.

Note that this is an advanced use case and it is recommended that you already know how to use the speedtest with a single server.

We must distinguish 2 types of servers:

  • Frontend server: hosts the UI, the JS files, and optionally telemetry and results sharing stuff. You only need 1 of these, and this is the server that your clients will first connect to.
  • Test backends: the servers used to actually perform the test. There can be 1+ of these, and they only host the backend files.

Frontend server

This is the server that your users will first connect to. It hosts the UI, the JS files, and optionally telemetry and results sharing stuff.

Requirements:

  • Apache 2 (nginx and IIS also supported). A fast connection is not mandatory, but is still recommended
  • PHP 5.4 or newer
  • If you want to store test results (telemetry), one of the following:
    • MySQL/MariaDB and the mysqli PHP module
    • PostgreSQL and its PHP PDO module
    • SQLite 3 and its PHP PDO module
  • If you want to enable results sharing:
    • FreeType 2 and its PHP module (this is usually installed automatically by most distros)

To install the speedtest frontend, copy the following files to your web server:

  • speedtest.js
  • speedtest_worker.js
  • Optionally, the results folder
  • One of the multipleServers examples (the best starting points are example-multipleServers-pretty.html if you don't want to use telemetry and results sharing, example-multipleServers-full.html if you want to use them). Rename the example you choose to index.html

Important: The speedtest needs write permissions in the installation folder!

Server list

Edit index.html, you will see a list of servers:

var SPEEDTEST_SERVERS=[
	{
		"name":"Speedtest Demo Server 1", //user friendly name for the server
		"server":"//mpotdemo.fdossena.com/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
		"dlURL":"garbage.php",  //path to download test on this server (garbage.php or replacement)
		"ulURL":"empty.php",  //path to upload test on this server (empty.php or replacement)
		"pingURL":"empty.php",  //path to ping/jitter test on this server (empty.php or replacement)
		"getIpURL":"getIP.php"  //path to getIP on this server (getIP.php or replacement)
	},
	{
		"name":"Speedtest Demo Server 2",
		"server":"//mpotdemo2.fdossena.com/",
		"dlURL":"garbage.php",
		"ulURL":"empty.php",
		"pingURL":"empty.php",
		"getIpURL":"getIP.php"
	}
	//add other servers here, comma separated
];

Replace the demo servers with your test points. Each server in the list is an object containing:

  • "name": user friendly name for this test point
  • "server": URL to the server. If your server only supports HTTP or HTTPS, put http:// or https:// at the beginning, respectively; if it supports both, put // at the beginning and it will be replaced automatically
  • "dlURL": path to the download test on this server (garbage.php or replacement)
  • "ulURL": path to the upload test on this server (empty.php or replacement)
  • "pingURL": path to the ping test on this server (empty.php or replacement)
  • "getIpURL": path to getIP on this server (getIP.php or replacement)

None of these parameters can be omitted.

Important: You can't mix HTTP with HTTPS; if the frontend uses HTTP, you won't be able to connect to HTTPS backends, and viceversa.

Important: For HTTPS, all your servers must have valid certificates or the browser will refuse to connect

Important: Don't use my demo servers, they're slow!

If your list of servers changes often, you might not want to have it hardcoded in the HTML file. LibreSpeed can load the server list from a JSON file. To do this, edit index.html and replace the list of servers with this:

var SPEEDTEST_SERVERS="your URL here";

The URL doesn't need to be complete, it can just point to a file in the current directory. The URL should point to a JSON file with the same format used above:

[
    {
        "name":...
    },
    ...
]

Important: The same origin policy applies to which URLs you can and cannot load with this method. If possible, it's best to just point it to a file on the current server.

Telemetry and results sharing

Telemetry is stored on the frontend server. The setup procedure is the same as the single server version.

Test backends

These are the servers that will actually be used to perform the test.

Requirements:

  • Apache 2 (nginx and IIS also supported). A fast internet connection is required (possibly gigabit), and the web server must accept large POST requests (up to 20MB)
  • PHP 5.4 or newer
  • OpenSSL and its PHP module (this is usually installed automatically by most distros)

To install a backend, simply copy all the files in the backend folder to your backend server.

Important: The speedtest needs write permissions in the installation folder!

ipinfo.io

The speedtest uses ipinfo.io to detect ISP and distance from server. This is completely optional and can be disabled if you want (see Speedtest settings), but it is enabled by default, and if you expect more than ~500 tests per day, you will need to sign up to ipinfo.io and edit getIP_ipInfo_apikey.php to set your access token.

IpInfo.io has kindly offered free access to their APIs for users of this project; if you're interested, contact me at info@fdossena.com and provide a description of what you intend to do with the project, and you'll get the API key.