-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path01-await.php
More file actions
31 lines (25 loc) · 757 Bytes
/
01-await.php
File metadata and controls
31 lines (25 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require __DIR__ . '/../vendor/autoload.php';
/**
* @param string $url
* @return Psr\Http\Message\ResponseInterface
* @throws Exception when HTTP request fails
*/
function requestHttp($url)
{
// This example uses an HTTP client
$browser = new React\Http\Browser();
// set up one request
$promise = $browser->get($url);
try {
// keep the loop running (i.e. block) until the response arrives
$result = Clue\React\Block\await($promise);
// promise successfully fulfilled with $result
return $result;
} catch (Exception $exception) {
// promise rejected with $exception
throw $exception;
}
}
$response = requestHttp('http://www.google.com/');
echo $response->getBody();