PHP code example of phasync / http-client

1. Go to this page and download the library: Download phasync/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/ */

    

phasync / http-client example snippets


use phasync\HttpClient\HttpClient;

$client = new HttpClient();
// Concurrent requests:
$response1 = $client->get('https://httpbin.org/get');
$response2 = $client->get('https://www.reddit.com/");
// All requests are performed in parallel using `curl_multi` under the hood.
echo $response1->getBody();
echo $resposne2->getBody();

$response = $client->post('https://httpbin.org/post', [
    'foo' => 'bar'
]);
echo $response->getBody();

$psr7Response = $client->sendRequest($psr7Request);

$client = new HttpClient([
    'followLocation' => true
]);
$response = $client->get('https://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com');

$client = new HttpClient([
    'timeoutMs' => 1000,
    'userAgent' => 'PhasyncClient/1.0'
]);