定制 aln/speedtest-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aln/speedtest-php

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.

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock php version

Installation

As standalone package

Download and install with

composer install

then run

./bin/speedtest

speedtest-php demo

(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

speedtest-php demo 2

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

aln/speedtest-php 适用场景与选型建议

aln/speedtest-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.39k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「speedtest bandwidth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aln/speedtest-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aln/speedtest-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 aln/speedtest-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-05-25