-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.php
55 lines (41 loc) · 1016 Bytes
/
io.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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/11/24 0024
* Time: 下午 1:34
*/
//I/O事件
//多进程编程
$sockfd = stream_socket_pair(AF_UNIX,SOCK_STREAM,0);
stream_set_blocking($sockfd[0],0);
stream_set_blocking($sockfd[1],0);
$pid = pcntl_fork();
//epoll
if ($pid==0){
// while (1){
//
// fwrite($sockfd[1],"hello");
// sleep(1);
// }
$eventBase = new \EventBase();
//I/O事件
$event = new \Event($eventBase,$sockfd[1],\Event::WRITE|\Event::PERSIST,function($fd,$what,$arg){
echo fwrite($fd,"china");
echo "\r\n";
},['a'=>'b']);
$event->add();
$events[] = $event;
$eventBase->dispatch();
}
else{
$eventBase = new \EventBase();
//I/O事件
$event = new \Event($eventBase,$sockfd[0],\Event::READ|\Event::PERSIST,function($fd,$what,$arg){
echo fread($fd,128);
echo "\r\n";
},['a'=>'b']);
$event->add();
$events[] = $event;
$eventBase->dispatch();//内部会执行循环
}