public static function createConnection(ConnectionOptions $options)
    {
        $endpoint = $options->getCurrentEndpoint();
        $context = stream_context_create();

        if (Endpoint::getType($endpoint) === Endpoint::TYPE_SSL) {
            // set further SSL options for the endpoint
            stream_context_set_option($context, 'ssl', 'verify_peer', $options[ConnectionOptions::OPTION_VERIFY_CERT]);
            @stream_context_set_option($context, 'ssl', 'verify_peer_name', $options[ConnectionOptions::OPTION_VERIFY_CERT_NAME]);
            stream_context_set_option($context, 'ssl', 'allow_self_signed', $options[ConnectionOptions::OPTION_ALLOW_SELF_SIGNED]);

            if ($options[ConnectionOptions::OPTION_CIPHERS] !== null) {
                // SSL ciphers
                stream_context_set_option($context, 'ssl', 'ciphers', $options[ConnectionOptions::OPTION_CIPHERS]);
            }
        }

        $fp = @stream_socket_client(
            Endpoint::normalize($endpoint),
            $errNo,
            $message,
            $options[ConnectionOptions::OPTION_TIMEOUT],
            STREAM_CLIENT_CONNECT,
            $context
        );

        if (!$fp) {
            throw new ConnectException(
                'cannot connect to endpoint \'' .
                $endpoint . '\': ' . $message, $errNo
            );
        }

        stream_set_timeout($fp, $options[ConnectionOptions::OPTION_TIMEOUT]);

        return $fp;
    }
public static function createConnection(ConnectionOptions $options)
    {
        $endpoint = $options->getCurrentEndpoint();
        $context = stream_context_create();

        if (Endpoint::getType($endpoint) === Endpoint::TYPE_SSL) {
            // set further SSL options for the endpoint
            stream_context_set_option($context, 'ssl', 'verify_peer', $options[ConnectionOptions::OPTION_VERIFY_CERT]);
            @stream_context_set_option($context, 'ssl', 'verify_peer_name', $options[ConnectionOptions::OPTION_VERIFY_CERT_NAME]);
            stream_context_set_option($context, 'ssl', 'allow_self_signed', $options[ConnectionOptions::OPTION_ALLOW_SELF_SIGNED]);

            if ($options[ConnectionOptions::OPTION_CIPHERS] !== null) {
                // SSL ciphers
                stream_context_set_option($context, 'ssl', 'ciphers', $options[ConnectionOptions::OPTION_CIPHERS]);
            }
        }

        $fp = @stream_socket_client(
            Endpoint::normalize($endpoint),
            $errNo,
            $message,
            $options[ConnectionOptions::OPTION_TIMEOUT],
            STREAM_CLIENT_CONNECT,
            $context
        );

        if (!$fp) {
            throw new ConnectException(
                'cannot connect to endpoint \'' .
                $endpoint . '\': ' . $message, $errNo
            );
        }

        stream_set_timeout($fp, $options[ConnectionOptions::OPTION_TIMEOUT]);

        return $fp;
    }
public static function createConnection ( ConnectionOptions $ options ) { $ endpoint = $ options -> getCurrentEndpoint ( ) ; $ context = stream_context_create ( ) ; if ( Endpoint :: getType ( $ endpoint ) === Endpoint :: TYPE_SSL ) { // set further SSL options for the endpoint stream_context_set_option ( $ context , 'ssl' , 'verify_peer' , $ options [ ConnectionOptions :: OPTION_VERIFY_CERT ] ) ; @ stream_context_set_option ( $ context , 'ssl' , 'verify_peer_name' , $ options [ ConnectionOptions :: OPTION_VERIFY_CERT_NAME ] ) ; stream_context_set_option ( $ context , 'ssl' , 'allow_self_signed' , $ options [ ConnectionOptions :: OPTION_ALLOW_SELF_SIGNED ] ) ; if ( $ options [ ConnectionOptions :: OPTION_CIPHERS ] !== null ) { // SSL ciphers stream_context_set_option ( $ context , 'ssl' , 'ciphers' , $ options [ ConnectionOptions :: OPTION_CIPHERS ] ) ; } } $ fp = @ stream_socket_client ( Endpoint :: normalize ( $ endpoint ) , $ errNo , $ message , $ options [ ConnectionOptions :: OPTION_TIMEOUT ] , STREAM_CLIENT_CONNECT , $ context ) ; if ( ! $ fp ) { throw new ConnectException ( 'cannot connect to endpoint \'' . $ endpoint . '\': ' . $ message , $ errNo ) ; } stream_set_timeout ( $ fp , $ options [ ConnectionOptions :: OPTION_TIMEOUT ] ) ; return $ fp ; }
Create a one-time HTTP connection by opening a socket to the server

It is the caller's responsibility to close the socket

@throws ConnectException

@param ConnectionOptions $options - connection options

@return resource - socket with server connection, will throw when no connection can be established
Create a one - time HTTP connection by opening a socket to the server