Connects to the Tor server.

@throws Exception\IOError

@return \TorControl\TorControl
357539
public function connect()
    {
        if ($this->connected) {
            return;
        }

        $this->socket = @fsockopen($this->options['hostname'], $this->options['port'], $errno, $errstr, $this->options['timeout']);
        if (!$this->socket) {
            throw new Exception\IOError($errno.' - '.$errstr);
        }

        $this->connected = true;

        return $this;
    }
1275232
public function open()
    {

        $this->log('open socket connection');
        $this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
        if ($this->socket) {
            socket_set_blocking($this->socket, 1);

            return true;
        } else {
            throw(new \Exception("{$errstr} (#{$errno})"));
        }
    }
1139614
public static function conn() {

		if (static::$_oConn !== NULL) {
			return static::$_oConn;
		}

		$aConfig = Config::get('memcache');

		$lServer =& $aConfig['server'][static::_CONFIG];
		if (!is_array($lServer)) {
			throw new \Exception('memcache config "' . static::_CONFIG . '" not found');
		}

		if ($aConfig['enable']) {
			$oConn = new \Memcached();
			$oConn->setOptions($aConfig['option']);
			$oConn->addServers($lServer);
		} else {
			$oConn = new MemcacheFake();
		}

		return static::$_oConn = $oConn;
	}
881710
private function connect()
        {
            $this->fd = fsockopen($this->serverHost, $this->serverPort, $errno, $errstr);

            if (!$this->fd) {
                throw new Exception('fsockopen returned: '.$errstr);
            }

            $key = $this->generateKey();

            $out  = "GET " . $this->serverPath . "/websocket/" . $this->session['sid'] . " HTTP/1.1\r\n";
            $out .= "Host: " . $this->serverHost . "\r\n";
            $out .= "Upgrade: WebSocket\r\n";
            $out .= "Connection: Upgrade\r\n";
            $out .= "Sec-WebSocket-Key: " . $key . "\r\n";
            $out .= "Sec-WebSocket-Version: 13\r\n";
            $out .= "Origin: *\r\n\r\n";

            fwrite($this->fd, $out);

            $res = fgets($this->fd);

            if ($res === false) {
                throw new Exception('Socket.io did not respond properly. Aborting...');
            }

            if ($subres = substr($res, 0, 12) != 'HTTP/1.1 101') {
                throw new Exception('Unexpected Response. Expected HTTP/1.1 101 got '.$subres.'. Aborting...');
            }

            while(true) {
                $res = trim(fgets($this->fd));
                if ($res === '') break;
            }

            if ($this->read) {
                if ($this->read() != '1::') {
                    throw new Exception('Socket.io did not send connect response. Aborting...');
                } else {
                    $this->stdout('info', 'Server report us as connected !');
                }
            }

            $this->heartbeatStamp = time();
        }
777851
public function connect()
  {
    if($this->stream !== null) return;

    $host     = strval($this->config["host"]);
    $port     = strval($this->config["port"]);
    $timeout  = intval($this->config["timeout"]);
    $blocking = intval($this->config["blocking"]);

    if(empty($this->config["ssh"]))
    {
      $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
      $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));

      $this->stream = @stream_socket_client($address, $errno, $errstr, $this->config["timeout"], STREAM_CLIENT_CONNECT, stream_context_create($options));

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
      }

      if(!empty($this->config["tls"]))
      {
        stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
      }
    }
    else
    {
      $this->session = @ssh2_connect($host, $port);

      if($this->session === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to establish secure shell connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }

      if(!@ssh2_auth_password($this->session, $this->config["username"], $this->config["password"]))
      {
        throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid loginname or password", 0x208);
      }

      $this->stream = @ssh2_shell($this->session, "raw");

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to open a secure shell on server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }
    }

    @stream_set_timeout($this->stream, $timeout);
    @stream_set_blocking($this->stream, $blocking ? 1 : 0);
  }
1335895
public function connect()
    {
        if ($this->connection != null) {
            $this->disconnect();
        }

        if ($this->config['persistent'] == true) {
            $tmp = null;
            $this->connection = @pfsockopen($this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']);
        } else {
            $this->connection = fsockopen($this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']);
        }

        if (!empty($errNum) || !empty($errStr)) {
            $this->error($errStr, $errNum);
        }

        $this->connected = is_resource($this->connection);

        return $this->connected;
    }
1000119
protected function connect()
        {
            if ( ! is_null($this->connection)) {
                return $this->connection;
            }
            $this->connection = @fsockopen($this->host, $this->port, $error, $message);
            if ($this->connection === false) {
                throw new Exception("Error making Redis connection: {$error} - {$message}");
            }
            $this->select($this->database);
            return $this->connection;
        }
167002
public function connect()
    {
        try {
            // Instantiate an S3 client
            $this->setS3Client(new S3Client([
                        'version' => $this->supplier['version'],
                        'region' => $this->supplier['region'],
                        'http'    => $this->supplier['http']
                    ]
                )
            );
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
498437
public function initialize()
    {
        try {
            $this->logger->debug('Connecting to the websocket');
            $this->engine->connect();
            $this->logger->debug('Connected to the server');

            $this->isConnected = true;
        } catch (SocketException $e) {
            $this->logger->error('Could not connect to the server', ['exception' => $e]);

            throw $e;
        }

        return $this;
    }
1011574
public function connect()
    {
        $this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);

        if (!$this->socket) {
            $this->lastResponse = $errstr;
            return false;
        }

        //set timeout
        stream_set_timeout($this->socket, 3, 0);

        // check authorization
        return $this->authorize();
    }
1354610
protected function connect() {
		if (!($this->connect = ftp_connect($this->options['host'], $this->options['port'], $this->options['timeout']))) {
			return $this->setError('Unable to connect to FTP server '.$this->options['host']);
		}
		if (!ftp_login($this->connect, $this->options['user'], $this->options['pass'])) {
			$this->umount();
			return $this->setError('Unable to login into '.$this->options['host']);
		}
		
		// switch off extended passive mode - may be usefull for some servers
		//@ftp_exec($this->connect, 'epsv4 off' );
		// enter passive mode if required
		$this->options['mode'] = 'active';
		ftp_pasv($this->connect, $this->options['mode'] == 'passive');

		// enter root folder
		if (!ftp_chdir($this->connect, $this->root))
		{
			$this->umount();
			return $this->setError('Unable to open root folder.');
		}
		
		$stat = array();
		$stat['name'] = $this->root;
		$stat['mime'] = 'directory';
		$this->filesCache[$this->root] = $stat;
		$this->cacheDir($this->root);
		
		return true;
	}
1352927
public function connect()
	{
		if($this->_ssl_mode === true)
		{
			if( ! function_exists('ftp_ssl_connect'))
			{
				throw new \RuntimeException('ftp_ssl_connect() function is missing.');
			}

			$this->_conn_id = @ftp_ssl_connect($this->_hostname, $this->_port, $this->_timeout);
		}

		else
		{
			$this->_conn_id = @ftp_connect($this->_hostname, $this->_port, $this->_timeout);
		}

		if ($this->_conn_id === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpConnectionException('Unable to establish a connection');
			}
			return false;
		}

		if ( ! $this->_login())
		{
			if ($this->_debug == true)
			{
				throw new \FtpConnectionException('Unable to login');
			}
		}

		// Set passive mode if needed
		if ($this->_passive == true)
		{
			ftp_pasv($this->_conn_id, true);
		}

		return $this;
	}
257849
public static function tor($proxy = '127.0.0.1:9050', $torControl = '127.0.0.1:9051')
    {
        return function (callable $handler) use ($proxy, $torControl) {
            return function (
                RequestInterface $request,
                array $options
            ) use ($handler, $proxy, $torControl) {
                $options = array_replace_recursive([
                    'proxy' => $proxy,
                    'curl'  => [
                        CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME
                    ]
                ], $options);

                if (array_key_exists('tor_new_identity', $options) && $options['tor_new_identity']) {
                    try {
                        self::requireNewTorIdentity($torControl, $options);
                    } catch (GuzzleException $e) {
                        if (@$options['tor_new_identity_exception']) {
                            throw $e;
                        }
                    }
                }

                return $handler($request, $options);
            };
        };
    }
204232
public function connect()
    {
        if ($this->connected === true) {
            return;
        }
        if ($this->_contextOption) {
            $context = stream_context_create($this->_contextOption);
            $this->_socket = stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg,
                30, STREAM_CLIENT_CONNECT, $context);
        } else {
            $this->_socket = stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg);
        }

        if (!$this->_socket) {
            Worker::safeEcho(new \Exception($errmsg));
            return;
        }
        
        stream_set_blocking($this->_socket, false);
        
        if ($this->onMessage) {
            Worker::$globalEvent->add($this->_socket, EventInterface::EV_READ, array($this, 'baseRead'));
        }
        $this->connected = true;
        // Try to emit onConnect callback.
        if ($this->onConnect) {
            try {
                call_user_func($this->onConnect, $this);
            } catch (\Exception $e) {
                Worker::log($e);
                exit(250);
            } catch (\Error $e) {
                Worker::log($e);
                exit(250);
            }
        }
    }
826364
protected function _Connect()
    {
        if ($this->_socket !== false) {
            // we are in persistent connection mode, so we have a socket
            // however, need to check whether it's still alive
            if (!@feof($this->_socket)) {
                return $this->_socket;
            }

            // force reopen
            $this->_socket = false;
        }

        $errno = 0;
        $errstr = '';
        $this->_connerror = false;

        if ($this->_path) {
            $host = $this->_path;
            $port = 0;
        } else {
            $host = $this->_host;
            $port = $this->_port;
        }

        if ($this->_timeout <= 0) {
            $fp = @fsockopen($host, $port, $errno, $errstr);
        } else {
            $fp = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
        }

        if (!$fp) {
            if ($this->_path) {
                $location = $this->_path;
            } else {
                $location = "{$this->_host}:{$this->_port}";
            }

            $errstr = trim($errstr);
            $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)";
            $this->_connerror = true;

            return false;
        }

        // send my version
        // this is a subtle part. we must do it before (!) reading back from searchd.
        // because otherwise under some conditions (reported on FreeBSD for instance)
        // TCP stack could throttle write-write-read pattern because of Nagle.
        if (!$this->_Send($fp, pack('N', 1), 4)) {
            fclose($fp);
            $this->_error = 'failed to send client protocol version';

            return false;
        }

        // check version
        list(, $v) = unpack('N*', fread($fp, 4));
        $v = (int) $v;
        if ($v < 1) {
            fclose($fp);
            $this->_error = "expected searchd protocol version 1+, got version '$v'";

            return false;
        }

        return $fp;
    }
794932
public function connect()
	{
		//check if there is a valid service instance
		if ( ! $this->validService()) 
		{

			//put this in try...catch block for better error handling
			try{
				
				//make a connection attempt
				$this->service = new \MySQLi($this->host,$this->username,$this->password,$this->database,$this->port);

				//check is the connection attempt returned an error
				if ($this->service->connect_error) 
				{
					//throw exception
					throw new MySQLException("Unable to connect to Database service with the provided settings");

				}

				//set the connection variable to true
				$this->connected = true;

			}

			//diplay error message
			catch(MySQLException $MySQLExceptionObject){

				//display error message
				$MySQLExceptionObject->errorShow();

			}
			
		}

		//return this connection instance
		return $this;

	}
231199
protected function connect()
    {
        $host = "{$this->socketProtocol}://{$this->hostname}";
        if ($this->socketPort) {
            $host .= ":{$this->socketPort}";
        }
        $socketStream = @stream_socket_client($host, $errorNumber, $errorMessage, $this->socketOptions['connectionTimeout']);
        if (!is_resource($socketStream)) {
            throw new \Exception("{$errorNumber}: Error connecting to socket: [{$errorMessage}]");
        }
        stream_set_timeout($socketStream, $this->socketOptions['streamTimeout']);
        stream_set_blocking($socketStream, true);
        $this->socketResource = $socketStream;
        return $this;
    }