【问题标题】:Guzzle 6 progress of downloadGuzzle 6下载进度
【发布时间】:2016-04-27 06:28:01
【问题描述】:

我想用 Guzzle 下载一个大文件并想跟踪进度。我不知道我是否必须以某种方式传递流或使用 RequestMediator。

我正在测试以下代码。

    $dl = 'http://archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64/current/images/netboot/mini.iso';
    $client = new Client([]);

    $request = new GuzzleHttp\Psr7\Request('get', $dl);
    $promise = $this->client->sendAsync($request, [
            'sink' => '/tmp/test.bin'
    ]);
    $promise->then(function  (Response $resp) use ( $fs) {
        echo 'Finished';
    }, function  (RequestException $e) {
    });
    $promise->wait();

如有提示,将不胜感激。

【问题讨论】:

    标签: php guzzle guzzle6


    【解决方案1】:

    虽然文档中没有提及,但您可以使用“进度”请求选项。

    可以在here找到对它的引用。

    $options = [
        'progress' => function ($dl_total_size, $dl_size_so_far, $ul_total_size, $ul_size_so_far) {
            // do something.
        }
    ];
    

    【讨论】:

    • 在我的例子中,这总是返回 0。
    猜你喜欢
    • 1970-01-01
    • 2019-12-25
    • 2015-11-17
    • 1970-01-01
    • 2016-04-15
    • 2015-10-29
    • 1970-01-01
    • 2016-09-19
    相关资源
    最近更新 更多