PHP code example of bohan / promise-http-client
1. Go to this page and download the library: Download bohan/promise-http-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bohan / promise-http-client example snippets
use Bohan\PromiseHttpClient\PromiseHttpClient;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\ResponseInterface;
$client = new PromiseHttpClient(HttpClient::create());
$promise = $client->request('GET', 'https://httpbin.org/status/429')->then(function (ResponseInterface $response) use ($client) {
if ($response->getStatusCode() < 300) {
return $response;
}
return $client->request('GET', 'https://httpbin.org/get');
});
/** @var ResponseInterface $response */
$response = $promise->wait();
echo $response->getStatusCode(); // 200