Skip to content

Add supports to consume servers with HTTP Partial Request using PHP

License

Notifications You must be signed in to change notification settings

davidasrocha/php-resumable-download

Repository files navigation

experimental Build Status

About library

This library implement the HTTP Partial Request to PHP projects, following the RFC 7233.

Initially this library is implementing only the Client to consume any server that implement the HTTP Partial Request. You can consume this library inside of your project, pay attention, you are responsible to manage exceptions and consume responses after any partial request.

Table of Contents

Installation

You need to pull the package via composer.

$ composer require davidasrocha/php-resumable-download

Usage

Basic HTTP Partial Request

Client

The client can be used to check server supports to HTTP Partial Request, execute the first partial request, execute a new partial request, re-execute partial request, and resume partial request.

use GuzzleHttp\Client;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

require __DIR__ . "/vendor/autoload.php";

$logger = new Logger('resume.request.client');
$logger->pushHandler(new StreamHandler(__DIR__ . '/logs/client.log'));

$client = new \PHP\ResumableDownload\Client(new Client(['base_uri' => 'http://127.0.0.1:8000/index.php']));
$client->setLogger($logger);

if ($client->serverSupportsPartialRequests()) {
    $client->start();
    $client->next();
    $client->next();
    $client->prev();
    $client->resume(2048, 4097);
    $client->next();
}

To get a response of the partial request, you can implement some bellow codes:

// execute the first partial request
$client->start();
$response = $client->current();

// execute a new partial request to the next part
$client->next();
$response = $client->current();

// execute a new partial request to the previous part
$client->next();
$client->next();
$client->prev();
$response = $client->current();

How can I run tests

This project has a Dockerfile and docker-compose.yml to easily run tests:

To start, inside of the project repository, you will run the command to build a new Docker image containing the PHP dependencies:

$ docker-compose build --force-rm --no-cache

Finally, you can run tests using this command:

$ docker-compose run php

About

Add supports to consume servers with HTTP Partial Request using PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published