-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimed-poll.php
45 lines (32 loc) · 842 Bytes
/
timed-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
<?php
use React\Promise\Deferred;
use React\EventLoop\Timer\Timer;
require "vendor/autoload.php";
$loop = React\EventLoop\Factory::create();
if (0) {
$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dnsResolver = $dnsResolverFactory->createCached('127.0.0.1', $loop);
$factory = new React\HttpClient\Factory();
$client = $factory->create($loop, $dnsResolver);
}
$loop->addPeriodicTimer (.25, function () {
static $count = 0;
$count ++;
echo $count, PHP_EOL;
if ($count == 10) {
posix_kill(posix_getpid(), SIGTERM);
}
});
$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();