Giter VIP home page Giter VIP logo

progress-subscriber's Introduction

Guzzle Progress Subscriber

Adds upload and download progress events to transfers.

<?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";

Installing

This project can be installed using Composer. Add the following to your composer.json:

{
    "require": {
        "guzzlehttp/progress-subscriber": "~1.0"
    }
}

Constructor Options

The GuzzleHttp\Subscriber\Progress\Progress class accepts the following constructor arguments:

$uploadProgress

(callable) A function that is invoked each time data is read from the upload stream. The event receives the expected number of bytes to transfer in the first argument, the total number of bytes transferred in the second argument, the client used to send the request in the third argument, and the request being sent in the fourth argument.

$downloadProgress

(callable) A function that is invoked each time data is written to the response body. The event receives the expected number of bytes to download in the first argument, the total number of bytes downloaded in the second argument, the client that sent the request in the third argument, the request that was sent in the fourth argument, and the response being received in the fifth argument.

progress-subscriber's People

Contributors

grahamcampbell avatar mtdowling avatar rud5g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.