Wrapper method for RiakClient::connect().

@see http://php.net/manual/en/mongoclient.connect.php
@return boolean
434509
public function connect()
    {
        $this->initialize();

        $riakClient = $this->riakClient;
        return $this->retry(function() use ($riakClient) {
            return $riakClient->connect();
        });
    }
777026
public function connect(): bool
    {
        if($this->connected)
        {
            return true;
        }
        $this->socket = stream_socket_client('unix://' . $this->socketFile, $errno, $errstr);
        if(false === $this->socket)
        {
            $this->connected = false;
            return false;
        }
        $this->connected = true;
        return true;
    }
1219208
public function connect($driverOptions = array()) {
        if ($this->pdo === null) {
            if (is_array($driverOptions) && !empty($driverOptions)) {
                $this->config['driverOptions']= array_merge($this->config['driverOptions'], $driverOptions);
            }
            try {
                $this->pdo= new \PDO($this->config['dsn'], $this->config['username'], $this->config['password'], $this->config['driverOptions']);
            } catch (\PDOException $xe) {
                $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $xe->getMessage(), '', __METHOD__, __FILE__, __LINE__);
                return false;
            } catch (\Exception $e) {
                $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
                return false;
            }

            $connected= (is_object($this->pdo));
            if ($connected) {
                $connectFile = XPDO_CORE_PATH . 'om/' . $this->config['dbtype'] . '/connect.inc.php';
                if (!empty($this->config['connect_file']) && file_exists($this->config['connect_file'])) {
                    $connectFile = $this->config['connect_file'];
                }
                if (file_exists($connectFile)) include ($connectFile);
            }
            if (!$connected) {
                $this->pdo= null;
            }
        }
        $connected= is_object($this->pdo);
        return $connected;
    }
729330
public function connect() {

		if($this->db !== null) return $this->db;

		try {

			$this->db = new \PDO(
				$this->config['datasource'],
				$this->config['username'],
				$this->config['password']
			);

			$this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

			return true;

		} catch(\PDOException $e) {
			throw new \HybridLogic\DB\Exception\ConnectionException($e);
		}

	}
292094
function(callback) {

  log('Connecting...');
  MongoClient.connect(dbUrl, dbOptions, function(err, dbConn) {
    
    if(err) {
      log('Cannot connect: ' + err);
      callback(err);
      return;
    } 
    
    log('Connected!');
    isConnected = true;
    db = dbConn;

    // http://stackoverflow.com/a/18715857/446681
    db.on('close', function() {
      log('Connection was closed!!!');
      isConnected = false;
    });

    log('Executing...');
    callback(null, db);
  
  });

}
776502
public function connect()
    {
        if ($this->_mongo) {
            return $this->_mongo;
        }

        if ($this->logger() && $this->logQueries()) {
            $logger = $this->buildStreamContext();
        } else {
            $logger = [];
        }

        $this->_mongo = Monga::connection($this->dns(), $this->getMongoConfig(), $logger);
        $this->_connected = true;
        return $this->_mongo;
    }
1139854
protected function _connect()
    {
        try {
            $this->_Redis = new Redis();
            if (!empty($this->_config['unix_socket'])) {
                $return = $this->_Redis->connect($this->_config['unix_socket']);
            } elseif (empty($this->_config['persistent'])) {
                $return = $this->_Redis->connect($this->_config['server'], $this->_config['port'], $this->_config['timeout']);
            } else {
                $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database'];
                $return = $this->_Redis->pconnect($this->_config['server'], $this->_config['port'], $this->_config['timeout'], $persistentId);
            }
        } catch (RedisException $e) {
            return false;
        }
        if ($return && $this->_config['password']) {
            $return = $this->_Redis->auth($this->_config['password']);
        }
        if ($return) {
            $return = $this->_Redis->select($this->_config['database']);
        }

        return $return;
    }
1324127
public static function connect() {
		if (self::$memcached === null) {
			$config = \Skeleton\Object\Config::$cache_handler_config;
			self::$memcached = new \Memcached();
			self::$memcached->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_IGBINARY);
			self::$memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
			self::$memcached->setOption(\Memcached::OPT_NO_BLOCK, true);
			self::$memcached->setOption(\Memcached::OPT_TCP_NODELAY, true);
			self::$memcached->addServers([
				[$config['hostname'], $config['port']]
			]);
		}

		return self::$memcached;
	}
996702
public function connect()
    {
        $func = $this->ssl ? 'ftp_ssl_connect' : 'ftp_connect';
        $this->_stream = $func($this->_host, $this->_port, $this->_timeout);

        if (!$this->_stream) {
            $this->error = 'Failed to connect '.$this->_host.'.';

            return false;
        }

        if (\ftp_login($this->_stream, $this->_user, $this->_pwd)) {
            \ftp_pasv($this->_stream, (bool)$this->passive);

            $this->system_type = \ftp_systype($this->_stream);

            return true;
        }

        $this->error = 'Failed to connect to '.$this->_host.' (login failed)';

        return false;
    }
14588
public function connect()
    {
        if ($this->isConnected()) {
            return true;
        }

        /* Create a TCP/IP socket. */
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket !== false) {
            $result = socket_connect($socket, 'e'.rand(1, 16).'.whatsapp.net', Constants::PORT);
            if ($result === false) {
                $socket = false;
            }
        }

        if ($socket !== false) {
            socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => Constants::TIMEOUT_SEC, 'usec' => Constants::TIMEOUT_USEC]);
            socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => Constants::TIMEOUT_SEC, 'usec' => Constants::TIMEOUT_USEC]);

            $this->socket = $socket;
            $this->eventManager()->fire('onConnect',
                [
                    $this->phoneNumber,
                    $this->socket,
                ]
            );
            $this->logFile('info', 'Connected to WA server');

            return true;
        } else {
            $this->logFile('error', 'Failed to connect WA server');
            $this->eventManager()->fire('onConnectError',
                [
                    $this->phoneNumber,
                    $this->socket,
                ]
            );

            return false;
        }
    }
1100206
public function connect()
    {
        /*
         The Server MUST process a second CONNECT Packet sent from a Client as a protocol violation
         and disconnect the Client [MQTT-3.1.0-2]

         So CONNECT SHOULD be a blocking connection.
         */

        $connect_retry_count = 0;
        $max_connect_retry_count = 10;
        do {
            $r = $this->socket->connect();
            if ($r) {
                break;
            }

            if (++$connect_retry_count > $max_connect_retry_count) {
                throw new Exception\ConnectError('Failed to connect to ' . $this->socket->getAddress());
            }
        } while (true);

        Debug::Log(Debug::INFO, 'connect(): Connection established.');

        $this->socket->set_blocking();

        /**
         * @var Message\CONNECT $connectobj
         */
        $connectobj = $this->getMessageObject(Message::CONNECT);

        if (!$this->connect_clean && empty($this->clientid)) {
            throw new Exception('Client id must be provided if Clean Session flag is set false.');
        }

        # default client id
        if (empty($this->clientid)) {
            $this->clientid = 'mqtt'.substr(md5(uniqid('mqtt', true)), 8, 16);
        }
        Debug::Log(Debug::DEBUG, 'connect(): clientid=' . $this->clientid);

        $connectobj->setKeepalive($this->keepalive);
        Debug::Log(Debug::DEBUG, 'connect(): keepalive=' . $this->keepalive);

        $connectobj->setAuth($this->username, $this->password);
        Debug::Log(Debug::DEBUG, 'connect(): username=' . $this->username . ' password=' . $this->password);

        $connectobj->setClean($this->connect_clean);

        if ($this->connect_will instanceof Will) {
            $connectobj->setWill($this->connect_will);
        }

        $length = 0;

        $bytes_written = $this->message_write($connectobj, $length);
        Debug::Log(Debug::DEBUG, 'connect(): bytes written=' . $bytes_written);

        /**
         * @var Message\CONNACK $connackobj
         */
        $connackobj = null;

        $connackobj = $this->message_read();

        Debug::Log(Debug::INFO, 'connect(): connected=' . ($connackobj->getMessageType() == Message::CONNACK ? 1 : 0));

        # save current time for ping
        $this->connected_time = time();

        # Call connect
        $this->call_handler('connack', array($this, $connackobj));

        return $connackobj;
    }
593821
public function connect(): bool
    {
        /** @var array $response */
        $response = $this->doPost('/api/v2.0/users/oauth/token', [
            'email' => $this->username,
            'password' => $this->password
        ]);

        // Define the token we want to use
        $this->storeToken($response['accessToken']);

        $response = $this->doGet('/api/v2.0/users/me/cookie-from-access-token');

        return true;
    }
1059329
public function connect()
    {
        try {
            $this->instance = DriverManager::getConnection($this->config, new Configuration());
            $this->createSchema();

            return true;
        } catch (DBALException $e) {
            throw new DriverConnectionException($e->getMessage());
        }
    }
705991
public static function connect() {
		if (self::$memcache === null) {
			$config = \Skeleton\Object\Config::$cache_handler_config;
			self::$memcache = new \Memcache();
			self::$memcache->connect($config['hostname'], $config['port']);
		}

		return self::$memcache;
	}
599020
public function connect($config = array())
    {
        if (empty($this->mongo)) {
            $options = array();
            if (!empty($config['options'])) {
                $options = $config['options'];
            }
            $this->mongo = new \MongoClient($config['dsn'], $options);

        }
    }
313135
public function connect()
    {

        if ($this->_connection && $this->_connection->connect()) {
            return true;
        }
        /**
         * Add required variables
         * Clear the connection parameters for security
         */
        $config = $this->_config['connection'] + array(
                'hostnames'  => 'localhost:27017'
        );

        unset($this->_config['connection']);

        /* Add Username & Password to server string */
        if (isset($config['username']) && isset($config['password'])) {
            $config['hostnames'] = $config['username'] . ':' . $config['password'] . '@' . $config['hostnames'] . '/' . $config['database'];
        }

        /* Add required 'mongodb://' prefix */
        if (strpos($config['hostnames'], 'mongodb://') !== 0) {
            $config['hostnames'] = 'mongodb://' . $config['hostnames'];
        }

        if (!isset($config['options']) || !is_array($config['options'])) {
            $config['options'] = array();
        }

        /* Create connection object, attempt to connect */
        $config['options']['connect'] = false;

        $class = '\MongoClient';
        if (!class_exists($class)) {
            $class = '\Mongo';
        }

        $this->_connection = new $class($config['hostnames'], $config['options']);

        /* Try connect */
        try {
            $this->_connection->connect();
        } catch (\MongoConnectionException $e) {
            throw new \Exception('Unable to connect to MongoDB server at ' . $config['hostnames']);
        }

        if (!isset($config['database'])) {
            throw new \Exception('No database specified in MangoDB Config');
        }

        $this->_db = $this->_connection->selectDB($config['database']);

        if(!$this->_db instanceof \MongoDB) {
            throw new \Exception('Unable to connect to database :: $_db is ' . gettype($this->_db));
        }
        
        $this->_connected = true;

        return true;
    }
617214
private function _connect()
    {
        $rcube = rcube::get_instance();

        if ($this->ready) {
            return true;
        }

        if (!is_array($this->prop['hosts'])) {
            $this->prop['hosts'] = array($this->prop['hosts']);
        }

        // try to connect + bind for every host configured
        // with OpenLDAP 2.x ldap_connect() always succeeds but ldap_bind will fail if host isn't reachable
        // see http://www.php.net/manual/en/function.ldap-connect.php
        foreach ($this->prop['hosts'] as $host) {
            // skip host if connection failed
            if (!$this->ldap->connect($host)) {
                continue;
            }

            // See if the directory is writeable.
            if ($this->prop['writable']) {
                $this->readonly = false;
            }

            $bind_pass = $this->prop['bind_pass'];
            $bind_user = $this->prop['bind_user'];
            $bind_dn   = $this->prop['bind_dn'];

            $this->base_dn        = $this->prop['base_dn'];
            $this->groups_base_dn = $this->prop['groups']['base_dn'] ?: $this->base_dn;

            // User specific access, generate the proper values to use.
            if ($this->prop['user_specific']) {
                // No password set, use the session password
                if (empty($bind_pass)) {
                    $bind_pass = $rcube->get_user_password();
                }

                // Get the pieces needed for variable replacement.
                if ($fu = ($rcube->get_user_email() ?: $this->prop['username'])) {
                    list($u, $d) = explode('@', $fu);
                }
                else {
                    $d = $this->mail_domain;
                }

                $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string

                // resolve $dc through LDAP
                if (!empty($this->prop['domain_filter']) && !empty($this->prop['search_bind_dn']) &&
                        method_exists($this->ldap, 'domain_root_dn')) {
                    $this->ldap->bind($this->prop['search_bind_dn'], $this->prop['search_bind_pw']);
                    $dc = $this->ldap->domain_root_dn($d);
                }

                $replaces = array('%dn' => '', '%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u);

                // Search for the dn to use to authenticate
                if ($this->prop['search_base_dn'] && $this->prop['search_filter']
                    && (strstr($bind_dn, '%dn') || strstr($this->base_dn, '%dn') || strstr($this->groups_base_dn, '%dn'))
                ) {
                    $search_attribs = array('uid');
                     if ($search_bind_attrib = (array)$this->prop['search_bind_attrib']) {
                         foreach ($search_bind_attrib as $r => $attr) {
                             $search_attribs[] = $attr;
                             $replaces[$r] = '';
                         }
                     }

                    $search_bind_dn = strtr($this->prop['search_bind_dn'], $replaces);
                    $search_base_dn = strtr($this->prop['search_base_dn'], $replaces);
                    $search_filter  = strtr($this->prop['search_filter'], $replaces);

                    $cache_key = 'DN.' . md5("$host:$search_bind_dn:$search_base_dn:$search_filter:"
                        .$this->prop['search_bind_pw']);

                    if ($this->cache && ($dn = $this->cache->get($cache_key))) {
                        $replaces['%dn'] = $dn;
                    }
                    else {
                        $ldap = $this->ldap;
                        if (!empty($search_bind_dn) && !empty($this->prop['search_bind_pw'])) {
                            // To protect from "Critical extension is unavailable" error
                            // we need to use a separate LDAP connection
                            if (!empty($this->prop['vlv'])) {
                                $ldap = new rcube_ldap_generic($this->prop);
                                $ldap->config_set(array('cache' => $this->cache, 'debug' => $this->debug));
                                if (!$ldap->connect($host)) {
                                    continue;
                                }
                            }

                            if (!$ldap->bind($search_bind_dn, $this->prop['search_bind_pw'])) {
                                continue;  // bind failed, try next host
                            }
                        }

                        $res = $ldap->search($search_base_dn, $search_filter, 'sub', $search_attribs);
                        if ($res) {
                            $res->rewind();
                            $replaces['%dn'] = key($res->entries(TRUE));

                            // add more replacements from 'search_bind_attrib' config
                            if ($search_bind_attrib) {
                                $res = $res->current();
                                foreach ($search_bind_attrib as $r => $attr) {
                                    $replaces[$r] = $res[$attr][0];
                                }
                            }
                        }

                        if ($ldap != $this->ldap) {
                            $ldap->close();
                        }
                    }

                    // DN not found
                    if (empty($replaces['%dn'])) {
                        if (!empty($this->prop['search_dn_default']))
                            $replaces['%dn'] = $this->prop['search_dn_default'];
                        else {
                            rcube::raise_error(array(
                                'code' => 100, 'type' => 'ldap',
                                'file' => __FILE__, 'line' => __LINE__,
                                'message' => "DN not found using LDAP search."), true);
                            continue;
                        }
                    }

                    if ($this->cache && !empty($replaces['%dn'])) {
                        $this->cache->set($cache_key, $replaces['%dn']);
                    }
                }

                // Replace the bind_dn and base_dn variables.
                $bind_dn              = strtr($bind_dn, $replaces);
                $this->base_dn        = strtr($this->base_dn, $replaces);
                $this->groups_base_dn = strtr($this->groups_base_dn, $replaces);

                // replace placeholders in filter settings
                if (!empty($this->prop['filter']))
                    $this->prop['filter'] = strtr($this->prop['filter'], $replaces);

                foreach (array('base_dn','filter','member_filter') as $k) {
                    if (!empty($this->prop['groups'][$k]))
                        $this->prop['groups'][$k] = strtr($this->prop['groups'][$k], $replaces);
                }

                if (is_array($this->prop['group_filters'])) {
                    foreach ($this->prop['group_filters'] as $i => $gf) {
                        if (!empty($gf['base_dn']))
                            $this->prop['group_filters'][$i]['base_dn'] = strtr($gf['base_dn'], $replaces);
                        if (!empty($gf['filter']))
                            $this->prop['group_filters'][$i]['filter'] = strtr($gf['filter'], $replaces);
                    }
                }

                if (empty($bind_user)) {
                    $bind_user = $u;
                }
            }

            if (empty($bind_pass)) {
                $this->ready = true;
            }
            else {
                if (!empty($bind_dn)) {
                    $this->ready = $this->ldap->bind($bind_dn, $bind_pass);
                }
                else if (!empty($this->prop['auth_cid'])) {
                    $this->ready = $this->ldap->sasl_bind($this->prop['auth_cid'], $bind_pass, $bind_user);
                }
                else {
                    $this->ready = $this->ldap->sasl_bind($bind_user, $bind_pass);
                }
            }

            // connection established, we're done here
            if ($this->ready) {
                break;
            }

        }  // end foreach hosts

        if (!is_resource($this->ldap->conn)) {
            rcube::raise_error(array('code' => 100, 'type' => 'ldap',
                'file' => __FILE__, 'line' => __LINE__,
                'message' => "Could not connect to any LDAP server, last tried $host"), true);

            return false;
        }

        return $this->ready;
    }