OpenSwoole Hook SSL

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

The OpenSwoole\Runtime::HOOK_SSL flag will enable coroutine support for SSL sockets and streams. Support was added in OpenSwoole v4.2.0.

Example

<?php

Co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_SSL]);

Co::run(function()
{
    $host = 'host.domain.tld';
    $port = 1234;
    $timeout = 12;
    $cert = '/path/to/your/certchain/certchain.pem';

    $context = stream_context_create(
        array(
            'ssl' => array(
                'local_cert' => $cert,
            )
        )
    );

    if($fp = stream_socket_client(
        'ssl://' . $host . ':' . $port,
        $errno,
        $errstr,
        30,
        STREAM_CLIENT_CONNECT,
        $context
    ))
    {
        echo "connected\n";
    }
    else
    {
        echo "ERROR: $errno - $errstr \n";
    }
});
Last updated on August 31, 2022