opcua-client-ext-transport-https · master
Docs · API

Events

Three PSR-14 events emitted around each HTTPS POST — observe traffic, time it, or audit failures without subclassing the transport.

Pass a Psr\EventDispatcher\EventDispatcherInterface to the HttpsTransport constructor and three events fire around each POST. When the dispatcher argument is null nothing is constructed — zero overhead.

All event classes live under PhpOpcua\Client\ExtTransportHttps\Event\, are final readonly, and carry only fields that are safe to log (no request body).

HttpsRequestSent

php HttpsRequestSent
final readonly class HttpsRequestSent
{
    public function __construct(
        public string $url,
        public string $contentType,
        public int $bodyLength,
    );
}

Dispatched just before the POST hits the wire. Useful for tracing, metrics, sampling.

HttpsResponseReceived

php HttpsResponseReceived
final readonly class HttpsResponseReceived
{
    public function __construct(
        public string $url,
        public int $statusCode,
        public int $bodyLength,
    );
}

Dispatched after a 2xx response, before the encoding strategy decodes the body. Pair it with HttpsRequestSent for round-trip timing.

HttpsRequestFailed

php HttpsRequestFailed
final readonly class HttpsRequestFailed
{
    public function __construct(
        public string $url,
        public int $statusCode,         // 0 = network-level failure
        public Throwable $cause,        // the originating exception
    );
}

Dispatched in two cases:

  • statusCode === 0 — the HTTP client raised HttpsRequestException (DNS, connect, TLS, read timeout). cause is the HttpsRequestException itself.
  • statusCode > 0 — the server returned a non-2xx. cause is the HttpsStatusException carrying responseBody for triage.

The transport re-throws after dispatching, so a handler can audit and let the exception flow to the application code naturally.

Ordering guarantees

For one transport->send():

Outcome Events
2xx HttpsRequestSentHttpsResponseReceived
Non-2xx HttpsRequestSentHttpsRequestFailed (statusCode > 0)
Network error HttpsRequestSentHttpsRequestFailed (statusCode = 0)
HEL frame (fake ACK locally) no events — no HTTP traffic generated

Dispatcher errors are swallowed

If your dispatcher throws, the transport logs a WARNING and continues — event delivery never breaks the OPC UA round-trip.