定制 graftype/speedtest-php 二次开发

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

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

graftype/speedtest-php

Composer 安装命令:

composer require graftype/speedtest-php

包简介

Speedtest.net for PHP | Library and command line interface

README 文档

README

Library and command line interface to run server-side speedtests via Speedtest.net from cli or web interface.

demo

This library is an updated version of aln-1/speedtest-php ported from the Python version sivel/speedtest-cli.

Latest Version Total Downloads License PHP Version

Navigation

Installation

How to install library to existing project using Composer

Since, our repository are public package we listed this repository on Packagist, that's mean we don't need to instruct Composer about which GitHub repository to look for inorder to find the package.

As project dependency

  • Install library using the following commands:
cd /path-to-app/
composer require graftype/speedtest-php

By updating composer.json file of your project

  • Open file named as composer.json in project folder /path-to-app/

  • Add following content to this file:

{
    "require": {
        // ---
        // Other packages
        // ---
        "graftype/speedtest-php": "^1.0"
    }
}
  • After that install library using the following commands:
cd /path-to-app/
composer update
  • /path-to-app/ project folder with existing composer.json file

How to install library to new project using Composer

Use following command, when you need to install library to new project using Composer:

  • If Composer not installed on your server/local machine, please follow this installation guide

  • Create blank file named as composer.json in project folder

  • Add following content to this file:

{
    "require": {
        "graftype/speedtest-php": "^1.0"
    }
}
  • After that install library using the following command:
cd /path-to-app/
composer update
  • /path-to-app/ project folder with existing composer.json file

Update

Use following command, when you need to update library to latest version:

cd /path-to-app/
composer update
  • /path-to-app/ project folder with existing composer.json file

Examples

Regular Usage

Minimal code

Code:

require 'vendor/autoload.php';

$speedtest = new Graftype\Speedtest\Speedtest();
$speedtest->getServers();
$speedtest->getBestServer();
$speedtest->download();
$speedtest->upload();

$results = $speedtest->results();

print_r($results);

Output:

Graftype\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

Code:

require 'vendor/autoload.php';

$config = new Graftype\Speedtest\Config();
$config->setCallback(function ($results) { print_r($results); });

$speedtest = new Graftype\Speedtest\Speedtest($config);
$speedtest->getServers();
$speedtest->getBestServer();
$speedtest->download();

Output:

Graftype\Speedtest\Result Object
(
    [latency:protected] => 4.40
    [download:protected] => 0
    [upload:protected] =>
    [bytesReceived:protected] => 0
    [bytesSent:protected] => 0
)

// More dump was here ...

```console
Graftype\Speedtest\Result Object
(
    [latency:protected] => 4.40
    [download:protected] => 27519752.835724
    [upload:protected] =>
    [bytesReceived:protected] => 37153149
    [bytesSent:protected] => 0
)

Units:

  • latency = ms
  • download / upload = bits/s
  • bytesReceived / bytesSent = bytes

We are showing here 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

CLI Usage

Console:

/path-to-app/vendor/bin/speedtest -h

Output:

usage: speedtest [-h] [--no-download] [--no-upload] [--single] [--bytes]
                 [--share] [--simple] [--json] [--list] [--server=SERVER]
                 [--exclude=EXCLUDE] [--source=SOURCE] [--timeout=TIMEOUT]
                 [--proxy=PROXY] [--version]

Command line interface to run server-side speedtests via Speedtest.net from cli or web interface.
--------------------------------------------------------------------------
https://github.com/graftype/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
  --proxy=PROXY         Use a proxied connection for test
  --version             Show the version number
  • /path-to-app/ project folder

Support

This is a developer's portal for Speedtest.net for PHP and should not be used for support. Please contact us via website chat if you need to submit a support request.

Paid Consultations & Personal Help

Please contact us via website chat if you need additional help with your own project, we will try to find best options for you.

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-02-12