[TOC]
* * * * *
## 1 事件文件
~~~
Workerman\Events\
EventInterface.php ;事件接口
Ev.php ;EV事件機制
Event.php ;Event事件機制
Libvent.php ;Libevent事件機制
Select.php ;Select事件機制
~~~
## 2 事件接口(EventInterface.php)
>[info] 成員變量
~~~
;讀事件,寫事件,信號事件,周期事件,定時事件
const EV_READ = 1;
const EV_WRITE = 2;
const EV_SIGNAL = 4;
const EV_TIMER = 8;
const EV_TIMER_ONCE = 16;
~~~
>[info] 成員方法
### add()注冊事件
public function add($fd, $flag, $func, $args = null);
> $fd:文件描述符
> $flag:事件類型
> $func:事件處理接口
> $args:參數
* * * * *
### del():注銷事件
public function del($fd, $flag);
> $fd:文件描述符
> $flag:事件類型
### clearAllTimer():移除所有定時器事件
public function clearAllTimer();
### loop():開啟事件循環
public function loop();
## 3 Ev事件機制(Ev.php)
>[info] 成員變量
~~~
;所有讀寫事件,信號事件,定時器事件
protected $_allEvents = array();
protected $_eventSignal = array();
protected $_eventTimer = array();
;定時器id
protected static $_timerId = 1;
~~~
>[info] 成員方法
### add($fd, $flag, $func, $args = null)注冊事件
`public function add($fd, $flag, $func, $args = null)`
> $fd:文件描述符
> $flag:事件類型
> $func:事件回調函數
> $args:參數
### del($fd, $flag) 注銷事件
`public function del($fd, $flag)`
> $fd:文件描述符
> $flag:事件類型
### timerCallback($event) 定時器回調接口
`public function timerCallback($event)`
> $event:事件參數
### clearAllTimer() 移除所有定時器
`public function clearAllTimer()`
### loop() 開啟事件循環
`public function loop()`
## 4 Event事件機制(Event.php)
>[info] 成員變量
~~~
;事件對象
protected $_eventBase = null;
;讀寫事件,信號事件,定時器事件
protected $_allEvents = array();
protected $_eventSignal = array();
protected $_eventTimer = array();
;定時器id
protected static $_timerId = 1;
~~~
>[info] 成員方法
### __construct():構造函數
`public function __construct()`
### add($fd, $flag, $func, $args=array()):注冊事件
`public function add($fd, $flag, $func, $args=array())`
### del($fd, $flag):注銷事件
`public function del($fd, $flag)`
### timerCallback($fd, $what, $param):定時器回調
`public function timerCallback($fd, $what, $param)`
### clearAllTimer():清除所有定時
public function clearAllTimer()
### loop():開啟事件循環
`public function loop()`
## 5 Livevent事件機制
>[info] 成員變量
~~~
;事件對象
protected $_eventBase = null;
;讀寫事件,信號事件,定時器事件
protected $_allEvents = array();
protected $_eventSignal = array();
protected $_eventTimer = array();
~~~
>[info] 成員方法
### __construct():構造函數
` public function __construct()`
### add($fd, $flag, $func, $args = array()):注冊事件
`public function add($fd, $flag, $func, $args = array())`
### del($fd, $flag:注銷事件
`public function del($fd, $flag)`
### timerCallback($_null1, $_null2, $timer_id):定時器回調
`protected function timerCallback($_null1, $_null2, $timer_id)`
### clearAllTimer():清除定時器事件
`public function clearAllTimer()`
### loop():開啟事件循環
`public function loop()`
## 6 Select事件機制
>[info] 成員變量
~~~
;讀寫事件,信號事件
public $_allEvents = array();
public $_signalEvents = array();
;讀描述符,寫描述符
protected $_readFds = array();
protected $_writeFds = array();
;定時器調度棧,定時器監聽,
protected $_scheduler = null;
protected $_task = array();
;定時器id
protected $_timerId = 1;
;延時
protected $_selectTimeout = 100000000;
;socket管道
protected $channel = array();
~~~
>[info] 成員方法
### __construct():構造函數
public function __construct()
### add($fd, $flag, $func, $args = array()):注冊事件
public function add($fd, $flag, $func, $args = array())
### signalHandler($signal):信號處理接口
public function signalHandler($signal)
### del($fd, $flag):注銷事件
public function del($fd, $flag)
### tick():定時器調度
protected function tick()
### clearAllTimer():清除定時器
public function clearAllTimer()
### loop():開啟事件循環
public function loop()
### 7 事件總結
事件機制實現對socket描述的事件回調處理
EventInterface.php 事件接口
Ev.php libev事件接口
Event.php Event擴展事件接口
Libevent.php Livevent擴展事件接口
Select.php Select事件接口
有關事件擴展機制 見基礎原理 事件循環