guzzlehttp / progress-subscriber
此包已被废弃,不再维护。未建议替代包。
发射上传和下载进度事件
1.1.0
2014-08-01 23:12 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~4.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2020-02-07 15:46:36 UTC
README
向传输添加上传和下载进度事件。
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Progress\Progress; $uploadCallback = function ($expected, $total, $client, $request) { printf("Upload: %d %% \r", 100 * ($total / $expected)); }; $downloadCallback = function ($expected, $total, $client, $request, $res) { printf("Download: %d %% \r", 100 * ($total / $expected)); }; $progress = new Progress($uploadCallback, $downloadCallback); $client = new Client(); $client->put('http://httpbin.org/put', [ 'body' => str_repeat('.', 10000), 'subscribers' => [$progress], ]); echo "\n";
安装
可以使用Composer安装此项目。在您的composer.json中添加以下内容
{ "require": { "guzzlehttp/progress-subscriber": "~1.0" } }
构造函数选项
GuzzleHttp\Subscriber\Progress\Progress
类接受以下构造函数参数
$uploadProgress
- (callable) 当从上传流中读取数据时被调用的函数。事件接收预期的传输字节数作为第一个参数,已传输的总字节数作为第二个参数,用于发送请求的客户端作为第三个参数,以及正在发送的请求作为第四个参数。
$downloadProgress
- (callable) 当将数据写入响应体时被调用的函数。事件接收预期的下载字节数作为第一个参数,已下载的总字节数作为第二个参数,发送请求的客户端作为第三个参数,发送的请求作为第四个参数,以及接收到的响应作为第五个参数。