forked from reactphp-legacy/socket-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02-https.php
35 lines (26 loc) · 960 Bytes
/
02-https.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
34
35
<?php
use React\EventLoop\Factory;
use React\SocketClient\TcpConnector;
use React\SocketClient\DnsConnector;
use React\SocketClient\SecureConnector;
use React\SocketClient\TimeoutConnector;
use React\SocketClient\ConnectionInterface;
require __DIR__ . '/../vendor/autoload.php';
$loop = Factory::create();
$factory = new \React\Dns\Resolver\Factory();
$resolver = $factory->create('8.8.8.8', $loop);
$tcp = new TcpConnector($loop);
$dns = new DnsConnector($tcp, $resolver);
$tls = new SecureConnector($dns, $loop);
// time out connection attempt in 3.0s
$tls = new TimeoutConnector($tls, 3.0, $loop);
$tls->create('www.google.com', 443)->then(function (ConnectionInterface $connection) {
$connection->on('data', function ($data) {
echo $data;
});
$connection->on('close', function () {
echo '[CLOSED]' . PHP_EOL;
});
$connection->write("GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n");
}, 'printf');
$loop->run();