aln/speedtest-php
最新稳定版本:v1.0.8
Composer 安装命令:
composer require aln/speedtest-php
包简介
Library and command line interface for testing internet bandwidth using speedtest.net
README 文档
README
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.
Installation
As standalone package
Download and install with
composer install
then run
./bin/speedtest
(IP adress was hidden for the demo)
As project dependency
composer require aln/speedtest-php
then run
./vendor/bin/speedtest
CLI Usage
$ ./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
Library
Minimal code
$ 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
With progress callback
$ 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)
Web demo
A one page demo is available at resources/demo.php
Credits
This project is ported from the Python version by Matt Martz
License
This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details
统计信息
- 总下载量: 6.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2020-05-25

