-
Notifications
You must be signed in to change notification settings - Fork 3
/
simple_query.php
33 lines (26 loc) · 1.01 KB
/
simple_query.php
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
32
33
<?php
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Productsup\GuzzleReactBridge\CurlMultiHandler;
use function Productsup\GuzzleReactBridge\run;
require __DIR__ . '/../vendor/autoload.php';
run(function ($loop) {
// Logger to show pretty messages with timestamps.
$logger = new Logger('default');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
$httpHandler = new CurlMultiHandler($loop);
$stack = HandlerStack::create($httpHandler);
$httpClient = new Client([
'handler' => $stack,
]);
$promise = $httpClient->getAsync('https://google.com')->then(
function ($result) use ($logger) { $logger->info('Query completed!'); },
function ($reason) use ($logger) { $logger->error('Query failed :('); }
);
/*
* The promise isn't completed yet, but it will be resolved in the future, the event loop will take care of it.
* We don't need to call Promise::wait()!
*/
});