forked from expressif/pecl-event-libevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libevent.php
58 lines (37 loc) · 903 Bytes
/
libevent.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
<?php
/* poll STDIN using basic API */
function foo($fd, $events, $arg)
{
static $i;
$i++;
if ($i == 10) {
event_base_loopexit($arg[1]);
}
var_dump(fread($fd, 1000));
}
$base = event_base_new();
$event = event_new();
$fd = STDIN;
var_dump(event_set($event, $fd, EV_READ | EV_PERSIST, "foo", array($event, $base)));
var_dump(event_set($event, $fd, EV_READ | EV_PERSIST, "foo", array($event, $base)));
event_base_set($event, $base);
var_dump(event_add($event));
var_dump(event_base_loop($base));
exit;
/* poll STDIN using event_buffer API */
function foo2($buf, $arg)
{
static $i;
$i++;
if ($i == 10) {
event_base_loopexit($arg);
}
var_dump($buf);
var_dump(event_buffer_read($buf, 10));
}
$base = event_base_new();
$b = event_buffer_new(STDIN, "foo2", NULL, "foo2", $base);
event_buffer_base_set($b, $base);
event_buffer_enable($b, EV_READ);
event_base_loop($base);
?>