public function open($address = false, $port = false)
    {
        $this->_connected = false;
        $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($this->_socket === false) {
            throw new TcpException(
            	'Error opening socket: ' . socket_strerror(socket_last_error())
            );
        }
        if ($this->_reuse) {
            socket_set_option ($this->_socket, SOL_SOCKET, SO_REUSEADDR, 1);
        }
        if ($address !== false) {
            if (!@socket_bind($this->_socket, $address, $port)) {
                throw new TcpException(
                	'Error binding socket: ' . socket_strerror(socket_last_error())
                );
            }
        }
        if ($this->_cTo > 0) {
            socket_set_nonblock($this->_socket);
            $timer = 0;
        } else {
            socket_set_block($this->_socket);
            $timer = -1;
        }
        $result = false;
        $this->_handler->beforeConnect();
        for(; $timer < $this->_cTo; $timer++)
        {
            $result = @socket_connect(
                $this->_socket, $this->_address, intval($this->_port)
            );
            if ($result === true) {
                break;
            }
            $error = socket_last_error();
            if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
                socket_close($this->_socket);
                $error = socket_strerror($error);
                $this->_socket = false;
                throw new TcpException('Could not connect: ' . $error);
            }
            // Use the select() as a sleep.
            $read = array($this->_socket);
            $write = null;
            $ex = null;
            $result = @socket_select($read, $write, $ex, 0, 650);
        }
        if (!$result) {
            $this->_handler->connectTimeout();
            socket_close($this->_socket);
            $this->_socket = false;
            return;
        }
        socket_set_nonblock($this->_socket);
        $this->_lastDataReadTime = $this->getMicrotime();
        $this->_connected = true;
        $this->_handler->connect();
        register_tick_function(array($this, 'process'));
    }
public function open($address = false, $port = false)
    {
        $this->_connected = false;
        $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($this->_socket === false) {
            throw new TcpException(
            	'Error opening socket: ' . socket_strerror(socket_last_error())
            );
        }
        if ($this->_reuse) {
            socket_set_option ($this->_socket, SOL_SOCKET, SO_REUSEADDR, 1);
        }
        if ($address !== false) {
            if (!@socket_bind($this->_socket, $address, $port)) {
                throw new TcpException(
                	'Error binding socket: ' . socket_strerror(socket_last_error())
                );
            }
        }
        if ($this->_cTo > 0) {
            socket_set_nonblock($this->_socket);
            $timer = 0;
        } else {
            socket_set_block($this->_socket);
            $timer = -1;
        }
        $result = false;
        $this->_handler->beforeConnect();
        for(; $timer < $this->_cTo; $timer++)
        {
            $result = @socket_connect(
                $this->_socket, $this->_address, intval($this->_port)
            );
            if ($result === true) {
                break;
            }
            $error = socket_last_error();
            if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
                socket_close($this->_socket);
                $error = socket_strerror($error);
                $this->_socket = false;
                throw new TcpException('Could not connect: ' . $error);
            }
            // Use the select() as a sleep.
            $read = array($this->_socket);
            $write = null;
            $ex = null;
            $result = @socket_select($read, $write, $ex, 0, 650);
        }
        if (!$result) {
            $this->_handler->connectTimeout();
            socket_close($this->_socket);
            $this->_socket = false;
            return;
        }
        socket_set_nonblock($this->_socket);
        $this->_lastDataReadTime = $this->getMicrotime();
        $this->_connected = true;
        $this->_handler->connect();
        register_tick_function(array($this, 'process'));
    }
public function open ( $ address = false , $ port = false ) { $ this -> _connected = false ; $ this -> _socket = socket_create ( AF_INET , SOCK_STREAM , SOL_TCP ) ; if ( $ this -> _socket === false ) { throw new TcpException ( 'Error opening socket: ' . socket_strerror ( socket_last_error ( ) ) ) ; } if ( $ this -> _reuse ) { socket_set_option ( $ this -> _socket , SOL_SOCKET , SO_REUSEADDR , 1 ) ; } if ( $ address !== false ) { if ( ! @ socket_bind ( $ this -> _socket , $ address , $ port ) ) { throw new TcpException ( 'Error binding socket: ' . socket_strerror ( socket_last_error ( ) ) ) ; } } if ( $ this -> _cTo > 0 ) { socket_set_nonblock ( $ this -> _socket ) ; $ timer = 0 ; } else { socket_set_block ( $ this -> _socket ) ; $ timer = - 1 ; } $ result = false ; $ this -> _handler -> beforeConnect ( ) ; for ( ; $ timer < $ this -> _cTo ; $ timer ++ ) { $ result = @ socket_connect ( $ this -> _socket , $ this -> _address , intval ( $ this -> _port ) ) ; if ( $ result === true ) { break ; } $ error = socket_last_error ( ) ; if ( $ error != SOCKET_EINPROGRESS && $ error != SOCKET_EALREADY ) { socket_close ( $ this -> _socket ) ; $ error = socket_strerror ( $ error ) ; $ this -> _socket = false ; throw new TcpException ( 'Could not connect: ' . $ error ) ; } // Use the select() as a sleep. $ read = array ( $ this -> _socket ) ; $ write = null ; $ ex = null ; $ result = @ socket_select ( $ read , $ write , $ ex , 0 , 650 ) ; } if ( ! $ result ) { $ this -> _handler -> connectTimeout ( ) ; socket_close ( $ this -> _socket ) ; $ this -> _socket = false ; return ; } socket_set_nonblock ( $ this -> _socket ) ; $ this -> _lastDataReadTime = $ this -> getMicrotime ( ) ; $ this -> _connected = true ; $ this -> _handler -> connect ( ) ; register_tick_function ( array ( $ this , 'process' ) ) ; }
Call this to open the connection to the server. Will also set the
socket non blocking and control the connection timeout.

@param string  $address Optional output ip address.
@param integer $port    Optional output port.

@throws TcpException
@return void
Call this to open the connection to the server . Will also set the socket non blocking and control the connection timeout .