Gozzle 6 download progress

I want to download a large file using Guzzle and want to track progress. I don't know if I should stream the stream or use the RequestMediator in some way.

I am testing the following code.

$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(); 

Hint will be appreciated.

+6
source share
1 answer

Despite the fact that it is not mentioned in the documentation, you can use the "progress" option.

Links to it can be found here .

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

Source: https://habr.com/ru/post/913394/


All Articles