38 lines
726 B
PHP
38 lines
726 B
PHP
<?php
|
|
|
|
require_once(dirname(__FILE__) .'/vendor/autoload.php');
|
|
|
|
// lib.php, helper functions
|
|
Lib\plain();
|
|
Lib\printf('https://sergio.am/code/www-tests');
|
|
|
|
use GuzzleHttp\Client;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
|
|
Lib\printf('client');
|
|
|
|
$client = new Client(['base_uri' => 'http://httpbin.org/']);
|
|
|
|
Lib\printf('promise');
|
|
|
|
$promise = $client->getAsync('/get');
|
|
|
|
Lib\printf('then');
|
|
|
|
$promise->then(
|
|
function (ResponseInterface $res) {
|
|
echo $res->getStatusCode() . "\n";
|
|
},
|
|
function (RequestException $e) {
|
|
echo $e->getMessage() . "\n";
|
|
echo $e->getRequest()->getMethod();
|
|
}
|
|
);
|
|
|
|
Lib\printf('wait');
|
|
|
|
$promise->wait();
|
|
|
|
Lib\printf('end');
|