-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll.php
73 lines (56 loc) · 1.42 KB
/
poll.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use React\Promise\Deferred;
require "vendor/autoload.php";
$loop = React\EventLoop\Factory::create();
echo get_class ($loop);
echo "\n";
$dnsResolverFactory = new React\Dns\Resolver\Factory();
//$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);
$dnsResolver = $dnsResolverFactory->createCached('127.0.0.1', $loop);
$factory = new React\HttpClient\Factory();
$client = $factory->create($loop, $dnsResolver);
for ($i = 0; $i < 3; $i++)
{
// echo get_class ($client), "\n";
// $request = $client->request('GET', 'http://10.0.0.1:6789/micro-service.php');
$request = $client->request('GET', 'http://dev.akond.net/react-php/micro-service.php');
$request->on('response', function ($response) {
$response->on ('data', function ($x) {
echo "x = $x\n";
});
if (0)
$response->on('data', function ($data, $response) {
if (0)
if (false == is_object ($data))
{
var_dump ($data);
}
else
{
$string = '';
while (false == $data->eof())
{
$string .= $data->read (1024);
}
echo $string, "\n\n";
}
});
});
$request->end();
}
if (0)
{
$pcntl = new MKraemer\ReactPCNTL\PCNTL($loop);
$pcntl->on(SIGTERM, function () {
// Clear some queue
// Write syslog
// Do ALL the stuff
echo 'Bye'.PHP_EOL;
die();
});
$pcntl->on(SIGINT, function () {
echo 'Terminated by console'.PHP_EOL;
die();
});
}
$loop->run();