Skip to content

SSL context option "alpn_protocols" is implemented since PHP 7.0 but undocumented #5401

@masakielastic

Description

@masakielastic

Affected page

https://www.php.net/manual/en/context.ssl.php

Current issue

The SSL stream context option alpn_protocols appears to be implemented
in ext/openssl but is not documented.

According to the PHP 7.0 changelog:

"Added 'alpn_protocols' SSL context option allowing encrypted client/server
streams to negotiate alternative protocols using the ALPN TLS extension
when built against OpenSSL 1.0.2 or newer. Negotiated protocol information
is accessible through stream_get_meta_data() output."

Source:
https://www.php.net/ChangeLog-7.php#PHP_7_0

This confirms that:

  • The option has been officially supported since PHP 7.0
  • It works for both client and server streams
  • It requires OpenSSL 1.0.2 or newer
  • The negotiated protocol can be retrieved via stream_get_meta_data()

Example usage:

$context = stream_context_create([
    'ssl' => [
        'alpn_protocols' => "h2,http/1.1",
    ],
]);

Since ALPN is required for HTTP/2 negotiation and widely used in modern TLS
deployments, documenting this option would be important for users.

Suggested improvement

alpn_protocols (string)
Specifies a comma-separated list of protocols to advertise to the peer during TLS Application-Layer Protocol Negotiation (ALPN). Requires OpenSSL 1.0.2 or newer. Available since PHP 7.0.

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions