Connects to the server

@param bool $test Whether to output the logs

@return Eden\Mail\Pop3
552642
public function connect($test = false)
    {
        Argument::i()->test(1, 'bool');

        if ($this->loggedin) {
            return $this;
        }

        $host = $this->host;

        if ($this->ssl) {
            $host = 'ssl://' . $host;
        }

        $errno  =  0;
        $errstr = '';

        $this->socket = fsockopen($host, $this->port, $errno, $errstr, self::TIMEOUT);

        if (!$this->socket) {
            //throw exception
            Exception::i()
                ->setMessage(Exception::SERVER_ERROR)
                ->addVariable($host.':'.$this->port)
                ->trigger();
        }

        $welcome = $this->receive();

        strtok($welcome, '<');
        $this->timestamp = strtok('>');
        if (!strpos($this->timestamp, '@')) {
            $this->timestamp = null;
        } else {
            $this->timestamp = '<' . $this->timestamp . '>';
        }

        if ($this->tls) {
            $this->call('STLS');
            if (!stream_socket_enable_crypto(
                $this->socket,
                true,
                STREAM_CRYPTO_METHOD_TLS_CLIENT
            )) {
                $this->disconnect();
                //throw exception
                Exception::i()
                    ->setMessage(Exception::TLS_ERROR)
                    ->addVariable($host.':'.$this->port)
                    ->trigger();
            }
        }

        if ($test) {
            $this->disconnect();
            return $this;
        }

        //login
        if ($this->timestamp) {
            try {
                $this->call(
                    'APOP '.$this->username
                    . ' '
                    . md5($this->timestamp . $this->password)
                );
                return;
            } catch (Argument $e) {
                // ignore
            }
        }

        $this->call('USER '.$this->username);
        $this->call('PASS '.$this->password);

        $this->loggedin = true;

        return $this;
    }
1332114
public function connect()
    {
        // Paramètre du service de connexion
        //@todo : supprimer ce paramètre ??
        $params = array(
            'arg0' => '1',
        );

        $this->client = $this->setClientSoap($this->URL_WSDL_AUTH);
        $result = $this->client->call('connect', $params, self::API_NAMESPACE, self::API_NAMESPACE, $this->createHeaders());

        if ($this->client->fault) {
            $this->errors[] = $this->client->faultstring;

            return false;
        } else {
            $err = $this->client->getError();
            if ($err) {
                $this->errors = $err;

                return $err;
            } else {
                if ($result == 'true') {
                    $this->isAuthenticated = true;

                    return true;
                } else {
                    return false;
                }
            }
        }
    }
15154
private function connect()
    {
        $server = $this->config['server'];
        if (isset($this->config['ssl']) && $this->config['ssl'] == true) {
            $server = 'ssl://' . $server;
        }

        stream_set_blocking(STDIN, 0);
        $this->socket = fsockopen($server, $this->config['port']);

        return (bool) $this->socket;
    }
70809
public function connectAction(Request $request)
    {
        $connect = $this->container->getParameter('hwi_oauth.connect');
        $hasUser = $this->getUser() ? $this->isGranted($this->container->getParameter('hwi_oauth.grant_rule')) : false;

        $error = $this->getErrorForRequest($request);

        // if connecting is enabled and there is no user, redirect to the registration form
        if ($connect && !$hasUser && $error instanceof AccountNotLinkedException) {
            $key = time();
            $session = $request->getSession();
            if (!$session->isStarted()) {
                $session->start();
            }

            $session->set('_hwi_oauth.registration_error.'.$key, $error);

            return $this->redirectToRoute('hwi_oauth_connect_registration', ['key' => $key]);
        }

        if ($error) {
            if ($error instanceof AuthenticationException) {
                $error = $error->getMessageKey();
            } else {
                $error = $error->getMessage();
            }
        }

        return $this->render('@HWIOAuth/Connect/login.html.twig', [
            'error' => $error,
        ]);
    }
336382
public function connect($host, $port = 80, $secure = false)
    {
        $this->log("Connecting to: ${host}:${port}");
        return parent::connect($host, $port, $secure);
    }
244046
private function connect()
    {
        if ($this->isConnected()) {
            return $this;
        }

        $connectionString = sprintf(
            'host=%s port=%d dbname=%s user=%s password=%s sslmode=%s',
            $this->host,
            $this->port,
            $this->dbName,
            $this->username,
            $this->password,
            $this->sslMode ? 'require' : 'disable'
        );

        $this->pgConn = pg_connect($connectionString);
        if ($this->pgConn === false) {
            throw $this->createException('Can`t connect');
        }

        $this->pendingConnection = false;

        return $this;
    }
988937
public function connect() {
        $host = $this->getAuthenticator()->getHost();
        $port = $this->getAuthenticator()->getPort();
        $this->setConnection(ssh2_connect($host, $port));
        if (false === $this->getConnection()) {
            throw $this->newFTPException("connection failed");
        }
        return $this;
    }
263341
public function _after(TestInterface $test)
    {
        if ($this->sessionStatus() === PHP_SESSION_ACTIVE) {
            $this->sessionDestroy();
        }

        if (isset($this->client) && $this->client instanceof Connector) {
            $this->client->reset();
            
            if (isset($this->baseRequest)) {
                $this->baseRequest = $this->client->getBaseRequest();
            }
            
            if (isset($this->baseResponse)) {
                $this->baseResponse = $this->client->getBaseResponse();
            }
        }

        parent::_after($test);
    }
698151
public function send($to, $message, $test=false, $callback=null)
    {
        return $this->client->send([
            'to' => $to,
            'message' => $message,
            'test' => $test,
            'callback' => null
        ]);
    }
435521
public function connect($host, $username, $password, $dbName, $replicaSet = '', $engine = '', $pConnect = false)
    {
        $authString = "";
        if ($username && $password) {
            $authString = "{$username}:{$password}@";
        }

        $replicaSet && $replicaSet = '?replicaSet=' . $replicaSet;
        $dsn = "mongodb://{$authString}{$host}/{$dbName}{$replicaSet}";

        return new Manager($dsn);
    }
1151924
public function connect()
    {
        $this->connection = ftp_connect($this->host);
        if (ftp_login($this->connection, $this->username, $this->password)) {
            if (ftp_chdir($this->connection, $this->getChdir()) && ftp_pasv($this->connection, $this->passive)) {
                $this->connected = true;
                return true;
            }
        }
        return false;
    }
651438
public function pasv($flag = true)
    {
        return ($this->isConnected() === true) ? ftp_pasv($this->getConnection(), $flag) : false;
    }
1299221
public function connect()
    {
        $this->log->debug("connect");

        $host = $this->ipv4_address_for_host($this->host, $this->port);
        if(!$host)
        {
          return FALSE;
        }

        // NOTE: This timeout doesn't apply to DNS, but does apply to the actual connecting
        $this->socket = @stream_socket_client("tcp://{$host}:{$this->port}", $errno, $errorMessage, self::CONNECT_TIMEOUT);
        $this->log->debug("connect after stream_socket_client, stream_socket_get_name: " . stream_socket_get_name($this->socket, TRUE));
        stream_set_timeout($this->socket, self::SEND_REPLY_TIMEOUT, 0);
        if(!$this->is_connected())
        {
          $this->log->error("Connection error $errno : $errorMessage");
          $this->disconnect(); // TODO: delay retry?
          return FALSE;
        }

        $hostname = gethostname();
        $pid = getmypid();
        $runtime = phpversion();
        $platform = preg_replace('/\s+/', '_', php_uname());
        $hello_and_auth_cmd =
          "hello version php/instrumental_agent/" . self::VERSION . " " .
          "hostname $hostname " .
          "pid $pid " .
          "runtime $runtime " .
          "platform $platform\n" .
          "authenticate $this->api_key\n";

        // $this->log->debug("Sleeping. Enable packet loss to test.");
        // sleep(10);
        // $this->log->debug("Resuming.");

        // NOTE: dropping packets didn't appear to affect sending
        $this->socket_send($hello_and_auth_cmd);

        $this->log->debug("connect fgets");
        // NOTE: dropping packets did affect fgets, and SEND_REPLY_TIMEOUT did apply
        $line = fgets($this->socket, 1024);
        $this->log->debug("connect $line");
        if($line != "ok\n")
        {
          $this->log->error("Sending hello failed.");
          $this->disconnect(); // TODO: delay retry?
          return FALSE;
        }

        $this->log->debug("connect fgets");
        $line = fgets($this->socket, 1024);
        $this->log->debug("connect $line");
        if($line != "ok\n")
        {
          $this->log->error("Authentication failed with key $this->api_key Please check your configuration." );
          $this->disconnect(); // TODO: delay retry?
          return FALSE;
        }
        return TRUE;
    }
48523
public function createClient($sandBox = false)
    {
        $client = new \SoapClient($this->wsdl, array(
            'soap_version' => SOAP_1_1,
            'classmap'     => $this->classmap
        ));

        $login    = $sandBox ? self::TEST_LOGIN    : $this->login;
        $password = $sandBox ? self::TEST_PASSWORD : $this->password;

        $client->__setSOAPHeaders($this->getSecurityHeader($login, $password));

        return $client;
    }
793699
public function addSkipped(Test $test)
    {
        $this->output->updateTable($test->pos->x, $test->pos->y, Graphite::MAGENTA);
        $this->skipped[] = $test;
    }
92420
public function setCheckSslHost($check = false)
    {
        // Make sure verify value is set to "2" for boolean argument
        // @see http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html
        if (true === $check) {
            $check = self::SSL_VERIFYHOST;
        }
        $this->checkSslHost = $check;

        return $this;
    }
547914
public static function popBeforeSmtp(
        $host,
        $port = false,
        $tval = false,
        $username = '',
        $password = '',
        $debug_level = 0
    ) {
        $pop = new POP3;
        return $pop->authorise($host, $port, $tval, $username, $password, $debug_level);
    }