public function add($fd, $flag, $func, $args = array())
    {
        $args = (array)$args;
        switch ($flag) {
            case EventInterface::EV_READ:
                return $this->addReadStream($fd, $func);
            case EventInterface::EV_WRITE:
                return $this->addWriteStream($fd, $func);
            case EventInterface::EV_SIGNAL:
                return $this->addSignal($fd, $func);
            case EventInterface::EV_TIMER:
                $timer_id = ++$this->_timerIdIndex;
                $timer_obj = $this->addPeriodicTimer($fd, function() use ($func, $args) {
                    call_user_func_array($func, $args);
                });
                $this->_timerIdMap[$timer_id] = $timer_obj;
                return $timer_id;
            case EventInterface::EV_TIMER_ONCE:
                $timer_id = ++$this->_timerIdIndex;
                $timer_obj = $this->addTimer($fd, function() use ($func, $args, $timer_id) {
                    unset($this->_timerIdMap[$timer_id]);
                    call_user_func_array($func, $args);
                });
                $this->_timerIdMap[$timer_id] = $timer_obj;
                return $timer_id;
        }
        return false;
    }
public function add($fd, $flag, $func, $args = array())
    {
        $args = (array)$args;
        switch ($flag) {
            case EventInterface::EV_READ:
                return $this->addReadStream($fd, $func);
            case EventInterface::EV_WRITE:
                return $this->addWriteStream($fd, $func);
            case EventInterface::EV_SIGNAL:
                return $this->addSignal($fd, $func);
            case EventInterface::EV_TIMER:
                $timer_id = ++$this->_timerIdIndex;
                $timer_obj = $this->addPeriodicTimer($fd, function() use ($func, $args) {
                    call_user_func_array($func, $args);
                });
                $this->_timerIdMap[$timer_id] = $timer_obj;
                return $timer_id;
            case EventInterface::EV_TIMER_ONCE:
                $timer_id = ++$this->_timerIdIndex;
                $timer_obj = $this->addTimer($fd, function() use ($func, $args, $timer_id) {
                    unset($this->_timerIdMap[$timer_id]);
                    call_user_func_array($func, $args);
                });
                $this->_timerIdMap[$timer_id] = $timer_obj;
                return $timer_id;
        }
        return false;
    }
public function add ( $ fd , $ flag , $ func , $ args = array ( ) ) { $ args = ( array ) $ args ; switch ( $ flag ) { case EventInterface :: EV_READ : return $ this -> addReadStream ( $ fd , $ func ) ; case EventInterface :: EV_WRITE : return $ this -> addWriteStream ( $ fd , $ func ) ; case EventInterface :: EV_SIGNAL : return $ this -> addSignal ( $ fd , $ func ) ; case EventInterface :: EV_TIMER : $ timer_id = ++ $ this -> _timerIdIndex ; $ timer_obj = $ this -> addPeriodicTimer ( $ fd , function ( ) use ( $ func , $ args ) { call_user_func_array ( $ func , $ args ) ; } ) ; $ this -> _timerIdMap [ $ timer_id ] = $ timer_obj ; return $ timer_id ; case EventInterface :: EV_TIMER_ONCE : $ timer_id = ++ $ this -> _timerIdIndex ; $ timer_obj = $ this -> addTimer ( $ fd , function ( ) use ( $ func , $ args , $ timer_id ) { unset ( $ this -> _timerIdMap [ $ timer_id ] ) ; call_user_func_array ( $ func , $ args ) ; } ) ; $ this -> _timerIdMap [ $ timer_id ] = $ timer_obj ; return $ timer_id ; } return false ; }
Add event listener to event loop.

@param $fd
@param $flag
@param $func
@param array $args
@return bool
Add event listener to event loop .