opcua-client-ext-transport-pubsub · v4.4.x
Docs · API

Transports

The UDP transport, its socket options, and the PubSubTransportInterface contract you implement to add MQTT, AMQP, or anything else.

A transport receives raw bytes and hands them to the kernel as a ReceivedPayload. The package ships UdpTransport; any other medium plugs in through PubSubTransportInterface.

UdpTransport

Built on ext-sockets. Supports UDP unicast and IPv4 multicast.

method · public
returns void
__construct(string \$endpoint, ?UdpOptions \$options = null)
Parameters
endpoint
string required

opc.udp://host:port. A multicast host (e.g. 239.0.0.1) makes the socket join that group; any other host binds for unicast.

options
?UdpOptions optional

Socket tuning. Defaults to new UdpOptions().

On open() the transport binds the socket, sets SO_REUSEADDR (when enabled), applies the receive buffer and TTL, and — for a multicast endpoint — joins the group via MCAST_JOIN_GROUP, falling back to IP_ADD_MEMBERSHIP on older stacks. poll() reads with a socket_select timeout and returns a ReceivedPayload (or null when nothing arrived in the window).

UdpOptions

Readonly tuning struct, all parameters optional:

Constructor
interface
string optional

Local interface address to bind / join on. Default '0.0.0.0' (all interfaces). Set to a specific NIC IP to scope multicast membership.

receiveBufferSize
int optional

SO_RCVBUF in bytes. Default 65536. Raise it for high-rate publishers to avoid datagram drops.

ttl
int optional

Multicast TTL / hop limit. Default 32.

reuseAddress
bool optional

Set SO_REUSEADDR so several subscribers can bind the same group/port. Default true.

php scoped multicast
use PhpOpcua\Client\ExtTransportPubSub\Transport\UdpTransport;
use PhpOpcua\Client\ExtTransportPubSub\Transport\UdpOptions;

$transport = new UdpTransport(
    'opc.udp://239.0.0.1:4840',
    new UdpOptions(interface: '10.0.0.5', receiveBufferSize: 262144),
);

ReceivedPayload

What a transport returns from poll(). Readonly:

Property Type Meaning
data string The raw datagram bytes
sourceUri string Identifier of where it came from (the transport URI)
receivedAt float Receive timestamp (microtime(true))
metadata array Optional transport-specific extras (default [])

Writing a custom transport

Implement PubSubTransportInterface to receive PubSub over a different medium (MQTT, AMQP, WebSocket, a file replay…):

method · public
returns void
open(): void

Open the medium. Throw UnsupportedTransportException if it cannot be opened.

method · public
returns void
close(): void

Release resources. Should be idempotent.

method · public
returns ?ReceivedPayload
poll(int \$timeoutMs): ?ReceivedPayload

Wait up to $timeoutMs for one message; return a ReceivedPayload or null on timeout. Must not block longer than the timeout.

method · public
returns bool
isOpen(): bool

Whether the transport is currently open.

method · public
returns string
transportUri(): string

A stable identifier used as sourceUri / transportUri in payloads and events.

Hand your transport to SubscriberBuilder::listenOn([$myTransport], $readers).

Decoding is the codec's job

A transport only moves bytes. Decoding (UADP/JSON) and security are handled downstream by the codec and the kernel — your transport never parses a NetworkMessage.