Library and command line interface for testing internet bandwidth using speedtest.net.
The goal of this project is to run server-side speedtest, from cli or web interface.
Download and install with
composer install
then run
./bin/speedtest
(IP adress was hidden for the demo)
composer require aln/speedtest-php
then run
./vendor/bin/speedtest
$ ./bin/speedtest -h
usage: speedtest [-h] [--no-download] [--no-upload] [--single] [--bytes]
[--share] [--simple] [--json] [--list] [--server=SERVER]
[--exclude=EXCLUDE] [--source=SOURCE] [--timeout=TIMEOUT]
[--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/aln-1/speedtest-php
optional arguments:
-h, --help show this help message and exit
--no-download Do not perform download test
--no-upload Do not perform upload test
--single Only use a single connection instead of multiple. This
simulates a typical file transfer
--bytes Display values in bytes instead of bits. Does not
affect the image generated by --share, nor output from
--json
--share Generate and provide a URL to the speedtest.net share
results image
--simple Suppress verbose output and progress, only shows results
--json Output in JSON format. Speeds listed in bits and not
affected by --bytes. Can be combined with --simple
to supress progress
--list Display a list of speedtest.net servers sorted by
distance
--server=SERVER Specify a server ID to test against. Can be comma
separated values
--exclude=EXCLUDE Exclude a server from selection. Can be comma
separated values
--source=SOURCE Source IP address to bind to or interface name
--timeout=TIMEOUT HTTP timeout in seconds, default 10
--version Show the version number
$ php -a
Interactive shell
php > require 'vendor/autoload.php';
php > $speedtest = new Aln\Speedtest\Speedtest();
php > $speedtest->getServers();
php > $speedtest->getBestServer();
php > $speedtest->download();
php > $speedtest->upload();
php > $results = $speedtest->results();
php > print_r($results);
Aln\Speedtest\Result Object
(
[latency:protected] => 4.57
[download:protected] => 47888585.578516
[upload:protected] => 64841042.860629
[bytesReceived:protected] => 59881235
[bytesSent:protected] => 82579808
)
Units:
- latency = ms
- download / upload = bits/s
- bytesReceived / bytesSent = bytes
$ php -a
Interactive shell
php > require 'vendor/autoload.php';
php > $config = new Aln\Speedtest\Config();
php > $config->setCallback(function ($results) { print_r($results); });
php > $speedtest = new Aln\Speedtest\Speedtest($config);
php > $speedtest->getServers();
php > $speedtest->getBestServer();
php > $speedtest->download();
Aln\Speedtest\Result Object
(
[latency:protected] => 4.40
[download:protected] => 0
[upload:protected] =>
[bytesReceived:protected] => 0
[bytesSent:protected] => 0
)
// More dump was here ...
Aln\Speedtest\Result Object
(
[latency:protected] => 4.40
[download:protected] => 27519752.835724
[upload:protected] =>
[bytesReceived:protected] => 37153149
[bytesSent:protected] => 0
)
(showing only first and last callback results from the download method)
A one page demo is available at resources/demo.php
This project is ported from the Python version by Matt Martz
This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details