src/Server/DefaultServerFactory.php
public function create(string $host, int $port = null, array $options = []): Server
    {
        $protocol = (string) ($options['protocol'] ?? (null === $port ? 'unix' : 'tcp'));
        $autoClose = (bool) ($options['auto_close'] ?? true);
        $queue = (int) ($options['backlog'] ?? (defined('SOMAXCONN') ? SOMAXCONN : self::DEFAULT_BACKLOG));
        $pem = (string) ($options['pem'] ?? '');
        $passphrase = ($options['passphrase'] ?? '');
        $name = (string) ($options['name'] ?? '');

        $verify = (string) ($options['verify_peer'] ?? self::DEFAULT_VERIFY_PEER);
        $allowSelfSigned = (bool) ($options['allow_self_signed'] ?? self::DEFAULT_ALLOW_SELF_SIGNED);
        $verifyDepth = (int) ($options['verify_depth'] ?? self::DEFAULT_VERIFY_DEPTH);

        $context = [];

        $context['socket'] = [
            'bindto' => Socket\makeName($host, $port),
            'backlog' => $queue,
            'ipv6_v6only' => true,
            'so_reuseaddr' => (bool) ($options['reuseaddr'] ?? false),
            'so_reuseport' => (bool) ($options['reuseport'] ?? false),
        ];

        if ('' !== $pem) {
            if (!file_exists($pem)) {
                throw new InvalidArgumentError('No file found at given PEM path.');
            }

            $context['ssl'] = [
                'verify_peer' => $verify,
                'verify_peer_name' => $verify,
                'allow_self_signed' => $allowSelfSigned,
                'verify_depth' => $verifyDepth,
                'local_cert' => $pem,
                'disable_compression' => true,
                'SNI_enabled' => true,
                'SNI_server_name' => $name,
                'peer_name' => $name,
            ];

            if ('' !== $passphrase) {
                $context['ssl']['passphrase'] = $passphrase;
            }
        }

        $context = stream_context_create($context);

        $uri = Socket\makeUri($protocol, $host, $port);
        // Error reporting suppressed since stream_socket_server() emits an E_WARNING on failure (checked below).
        $socket = @stream_socket_server($uri, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);

        if (!$socket || $errno) {
            throw new FailureException(sprintf('Could not create server %s: Errno: %d; %s', $uri, $errno, $errstr));
        }

        return new BasicServer($socket, $autoClose);
    }
public function create(string $host, int $port = null, array $options = []): Server
    {
        $protocol = (string) ($options['protocol'] ?? (null === $port ? 'unix' : 'tcp'));
        $autoClose = (bool) ($options['auto_close'] ?? true);
        $queue = (int) ($options['backlog'] ?? (defined('SOMAXCONN') ? SOMAXCONN : self::DEFAULT_BACKLOG));
        $pem = (string) ($options['pem'] ?? '');
        $passphrase = ($options['passphrase'] ?? '');
        $name = (string) ($options['name'] ?? '');

        $verify = (string) ($options['verify_peer'] ?? self::DEFAULT_VERIFY_PEER);
        $allowSelfSigned = (bool) ($options['allow_self_signed'] ?? self::DEFAULT_ALLOW_SELF_SIGNED);
        $verifyDepth = (int) ($options['verify_depth'] ?? self::DEFAULT_VERIFY_DEPTH);

        $context = [];

        $context['socket'] = [
            'bindto' => Socket\makeName($host, $port),
            'backlog' => $queue,
            'ipv6_v6only' => true,
            'so_reuseaddr' => (bool) ($options['reuseaddr'] ?? false),
            'so_reuseport' => (bool) ($options['reuseport'] ?? false),
        ];

        if ('' !== $pem) {
            if (!file_exists($pem)) {
                throw new InvalidArgumentError('No file found at given PEM path.');
            }

            $context['ssl'] = [
                'verify_peer' => $verify,
                'verify_peer_name' => $verify,
                'allow_self_signed' => $allowSelfSigned,
                'verify_depth' => $verifyDepth,
                'local_cert' => $pem,
                'disable_compression' => true,
                'SNI_enabled' => true,
                'SNI_server_name' => $name,
                'peer_name' => $name,
            ];

            if ('' !== $passphrase) {
                $context['ssl']['passphrase'] = $passphrase;
            }
        }

        $context = stream_context_create($context);

        $uri = Socket\makeUri($protocol, $host, $port);
        // Error reporting suppressed since stream_socket_server() emits an E_WARNING on failure (checked below).
        $socket = @stream_socket_server($uri, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);

        if (!$socket || $errno) {
            throw new FailureException(sprintf('Could not create server %s: Errno: %d; %s', $uri, $errno, $errstr));
        }

        return new BasicServer($socket, $autoClose);
    }
{@inheritdoc}