PHP code example of drewlabs / async-http

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

    

drewlabs / async-http example snippets


use function Drewlabs\Async\Future\await;
use function Drewlabs\Async\Http\createRequest;
use function Drewlabs\Async\Http\fetch;

// Creates the fetch client
$promise = fetch(createRequest('http://www.dneonline.com/calculator.asmx?wsdl', 'GET', null, []), ['debug' => true]); // Debugging should not be used in production

$response = await($promise);
printf("Content-Length: %d\n\r", strlen($response->getBody()));

use function Drewlabs\Async\Http\createRequest;
use function Drewlabs\Async\Http\fetch;

// Creates the fetch client
$promise = fetch(createRequest('http://www.dneonline.com/calculator.asmx?wsdl', 'GET', null, []), ['debug' => true]); // Debugging should not be used in production

// Provide then handlers
$promise->then(function($response) {
	printf($response->getBody());
	printf($response->getStatusCode());
});

// wait for request to complete response
$promise->wait();