www-tests/promises/simple.php

38 lines
726 B
PHP
Raw Normal View History

2019-11-23 13:17:04 +00:00
<?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');