PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test/unit
.gitignore
.scrutinizer.yml
LICENCE
README.md
circle.yml
composer.json
composer.lock
phpunit.xml

README.md

Asynchronous HTTP client with promises for PHP 7 projects.

Based on the client-side JavaScript fetch API.


Gitter chat Build status Code quality Code coverage Current version

Example usage: compute multiple HTTP requests in parallel.

<?php
$http = new \Gt\Fetch\Http();

$http->get("http://example.com/api/something.json")
->then(function($response) {
    if($response->status !== 200) {
        echo "Looks like there was a problem. Status code: "
            . $response->status . PHP_EOL;
        return;
    }

    return $response->json();
})
->then(function($json) {
    echo "Got JSON result length "
        . count($json->results)
        . PHP_EOL;

    echo "Name of first result: "
        . $json->results[0]->name
        . PHP_EOL;
});

$http->get("http://example.com/something.jpg")
->then(function($response) {
    return $response->blob();
})
->then(function($blob) {
    echo "Got JPG blob. Saving file." . PHP_EOL;
    file_put_contents("/tmp/something.jpg", $blob);
});

$http->all()->then(function() {
    echo "All HTTP calls have completed!" . PHP_EOL;
});