OpenSwoole\Coroutine\Http\Client->getPeerCert()

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

Declaration

<?php OpenSwoole\Coroutine\Http\Client->getPeerCert(): string|false

Parameters

None

Return

When successful, it returns X509 certificate information, when it fails it returns false.


Description

Obtain server-side certificate information.

This method can only be used once SSL has been completed and the handshake is successful.

The function openssl_x509_parse which is provided by the OpenSSL library can be used to parse the certificate information.

You must have installed OpenSwoole using --enable-openssl for this to work.


Example

<?php
use OpenSwoole\Coroutine\HTTP\Client;

co::run(function()
{
    // Enable SSL
    $client = new Client('https://Swoole.co.uk', 443, true);

    $client->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);

    $client->set(['timeout' => 1]);

    $client->setDefer(true);

    $client->get('/');

    // Show the SSL cert info
    var_dump($cli->getPeerCert());

    $client->close();
});
Last updated on September 1, 2022