Asynchronously connect to a TCP/TLS server.

@param ConnectionContext $ctx Connection context

@return \Generator
776461
public function connectAsync(ConnectionContext $ctx, string $header = ''): \Generator
    {
        $this->stream = yield $ctx->getStream($header);
        $this->memory_stream = fopen('php://memory', 'r+');

        return true;
    }
154905
protected function establishConnection($client, array $config)
    {
        $client->{Arr::get($config, 'persistent', false) === true ? 'pconnect' : 'connect'}(
            $config['host'], $config['port'], Arr::get($config, 'timeout', 0)
        );
    }
352419
public function getConnection($alias = null)
    {
        $message = null;

        if (null === $alias && empty($this->connections)) {
            $message = sprintf('There is no connection configured');
        } elseif (null !== $alias && !array_key_exists($alias, $this->connections)) {
            $message = sprintf('The connection with alias "%s" is not configured', $alias);
        }
        if ($message) {
            throw new InvalidConnectionException($message);
        }

        if (null === $alias) {
            return $this->getDefaultConnection();
        }

        return $this->connections[$alias];
    }
225921
public function launch(ContextInterface $ctx, ...$args): ProcessInstance
	{
		if ($this->executable) {
			$executable = $this->executable;

		} else if (PHP_OS === "Linux") {
			$finder = new ExecutableFinder();
			$executable = $finder->find(static::DEFAULT_LINUX_EXECUTABLE);
			if ($executable === null) {
				throw new RuntimeException(sprintf("Executable [%s] not found.", static::DEFAULT_LINUX_EXECUTABLE));
			}

		} else if (strncasecmp(PHP_OS, "Win", 3) === 0) {
			$finder = new ExecutableFinder();
			$executable = $finder->find(static::DEFAULT_WINDOWS_EXECUTABLE);
			if ($executable === null) {
				throw new RuntimeException(sprintf("Executable [%s] not found.", static::DEFAULT_WINDOWS_EXECUTABLE));
			}

		} else if (PHP_OS === "Darwin") {
			$candidateExecutables = [
				// Chrome Canary
				"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
				// Chrome Stable
				"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
			];

			$executable = null;
			foreach ($candidateExecutables as $candidateExecutable) {
				if (is_executable($candidateExecutable)) {
					$executable = $candidateExecutable;
					break;
				}
			}

			if ($executable === null) {
				throw new RuntimeException(sprintf("No OS X executable found."));
			}

		} else {
			throw new LogicException(sprintf("Operating system [%s] not supported.", PHP_OS));
		}

		return $this->launchWithExecutable($ctx, $executable, ...$args);
	}
1265529
public function timeout($timeout = null, $connectTimeout = null)
    {
        if(null !== $timeout)
        {
            $this->timeout = $timeout;
        }
        if(null !== $connectTimeout)
        {
            $this->connectTimeout = $connectTimeout;
        }
        return $this;
    }
1328875
public function connect($username , $password)
    {
        if ( ! $this->isConnected ) {
            try {
                $this->client->LogIn([ 'username' => $username , 'password' => $password ]);
                $this->isConnected = true;
            } catch ( SoapFault $ex ) {
                throw new ConnectException('Either an error occured when connecting to Livedocx, or the credentials you provided are wrong' , $ex);
            }
        }
        return $this;
    }
500493
protected function configureConnection($connectionConfig)
    {
        $this->validateConnectionConfig($connectionConfig);

        $options = [];
        if (isset($connectionConfig['options'])) {
            $options = $connectionConfig['options'];
        }

        $options['driver'] = $connectionConfig['type'];

        $dialectClass = $this->dialectMap[$connectionConfig['type']];

        /** @var IDialect $dialect */
        $dialect = new $dialectClass;

        $options['platform'] = $dialect;

        $connection = DriverManager::getConnection($options);

        $dialect->initConnection($connection);

        return [
            $connection,
            $dialect
        ];
    }
361781
public function setCurrentConnection($connection = null, $server = null)
    {
        $connectionKey = $connection instanceof ConnectionKey ? $connection : $this->credentials->createConnectionKey($connection, $server);
        if ($this->current === $connectionKey->toHandle()) {
            return;
        }

        $this->current = $connectionKey->toHandle();
        $this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
            $isCurrent = $connectionKey->is($connection->getConnectionKey());
            $connection->setCurrent($isCurrent);

            return $connection;
        });

        // Update events
        $this->bootstrapper->bootstrapUserCode();
    }
917467
public function connect(float $connectTimeout = 1.0): Stream
    {
        $errno  = 0;
        $errstr = '';
        $fsockopen = $this->fsockopen;
        $resource = $fsockopen(
                $this->prefix . $this->host,
                $this->port,
                $errno,
                $errstr,
                $connectTimeout
        );
        if (false === $resource) {
            throw new ConnectionFailure(
                    'Connect to ' . $this->prefix . $this->host . ':'. $this->port
                    . ' within ' . $connectTimeout . ' second'
                    . (1 == $connectTimeout ? '' : 's') . ' failed: '
                    . $errstr . ' (' . $errno . ').'
            );
        }

        return new Stream($resource, $this->usesSsl());
    }
623031
public static function factory($host, $port, $sendTimeout = null, $receiveTimeout = null, $framedTransport = false)
    {
        $socket = self::createSocket($host, $port, $sendTimeout, $receiveTimeout);
        $transport = self::createTransport($socket, $framedTransport);
        $protocol = new TBinaryProtocolAccelerated($transport);
        $client = new RestClient($protocol);
        $transport->open();

        return $client;
    }
1048609
protected function proxy() {
        if (!$this->context) {
            $this->context = new ExecutionContext(
                $this->version,
                $this->solution['flowSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
1351075
function initContext (DocumentContext $ctx)
  {
    $ctx->condenseLiterals     = $this->collapseWhitespace;
    $ctx->controllers          = $this->controllers;
    $ctx->controllerNamespaces = $this->controllerNamespaces;
    $ctx->registerTags ($this->tags);
    $ctx->setFilterHandler ($this->filterHandler);
    $ctx->getDataBinder ()->setContext ($ctx);
  }
295259
private function openConnectionAPNS($ctx)
    {
        $fp = false;

        // Open a connection to the APNS server
        try {
            $fp = stream_socket_client(
                $this->url,
                $err,
                $errstr,
                60,
                STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,
                $ctx
            );

            stream_set_blocking($fp, 0);

            if (!$fp) {
                $response = ['success' => false, 'error' => "Failed to connect: $err $errstr" . PHP_EOL];

                $this->setFeedback(json_decode(json_encode($response)));

            }

        } catch (\Exception $e) {
            //if stream socket can't be established, try again
            if ($this->canRetry()) {
                return $this->openConnectionAPNS($ctx);
            }

            $response = ['success' => false, 'error' => 'Connection problem: ' . $e->getMessage() . PHP_EOL];
            $this->setFeedback(json_decode(json_encode($response)));

        } finally {
            $this->resetAttempts();
            return $fp;
        }
    }
662297
private function connect()
    {
        if (is_null($this->connection)) {
            $this->connection = call_user_func($this->connectionFactory, $this->config);
        }

        return $this;
    }
791866
public function setContext(RequestContext $context)
    {
        if (null !== $this->generator) {
            $this->getGenerator()->setContext($context);
        }
        $this->context = $context;
    }
524912
public function newConnection($nodeUrl)
    {
        self::$connection = new Client($nodeUrl, ['timeout' => $this->wsTimeoutSeconds]);

        return self::$connection;
    }
945010
protected function prepare(Connection $connection)
	{
		$connection->setFetchMode($this->app['config']['database.fetch']);

		if ($this->app->bound('events'))
		{
			$connection->setEventDispatcher($this->app['events']);
		}

		// Here we'll set a reconnector callback. This reconnector can be any callable
		// so we will set a Closure to reconnect from this manager with the name of
		// the connection, which will allow us to reconnect from the connections.
		$connection->setReconnector(function($connection)
		{
			$this->reconnect($connection->getName());
		});

		return $connection;
	}