public function keepAlive()
        {
            while (is_resource($this->fd)) {
                if ($this->session['heartbeat_timeout'] > 0 && $this->session['heartbeat_timeout'] + $this->heartbeatStamp - 5 < time()) {
                    $this->send(self::TYPE_HEARTBEAT);
                    $this->heartbeatStamp = time();
                }

                $r = array($this->fd);
                $w = $e = null;

                if (stream_select($r, $w, $e, 5) == 0) {
                    continue;
                }

                $res    = $this->read();
                $sess   = explode(':', $res);

                if ((int) Arrays::first($sess) === self::TYPE_EVENT) {
                    unset(Arrays::first($sess), $sess[1], $sess[2]);

                    $response = json_decode(implode(':', $sess), true);
                    $name = $response['name'];
                    $data = Arrays::first($response['args']);

                    $this->stdout('debug', 'Receive event "' . $name . '" with data "' . $data . '"');

                    if (!empty($this->callbacks[$name])) {
                        foreach ($this->callbacks[$name] as $callback) {
                            call_user_func($callback, $data);
                        }
                    }
                }
            }
        }