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.
This library is an updated version of aln-1/speedtest-php ported from the Python version sivel/speedtest-cli.
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.jsonin 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 existingcomposer.jsonfile
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.jsonin 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 existingcomposer.jsonfile
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 existingcomposer.jsonfile
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
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 graftype/speedtest-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Laravel Media Popup to upload/view the files
Automatically scale down and rotate uploaded images for Silverstripe. This module is based on axllent's version.
Allow Fullscreen TinyMCE video embed, lazy loading and other features
Alfabank REST API integration
Static publishing queue to create static versions of pages for enhanced performance and security
统计信息
- 总下载量: 1.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-02-12

