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

Quick start

Describe your readers, hand the builder a callback, and listen. Three steps to a running PubSub subscriber.

  1. 01

    Describe the DataSet you expect

    A DataSetReaderConfig tells the subscriber which publisher/group/writer triple to accept and how to decode its fields. The field layout comes from a DataSetMetaData — load it from JSON, XML, binary, or fetch it from a server.

  2. 02

    Build the subscriber and attach a callback

    The callback signature is function (DataSetMessage $message, int|string $publisherId, int $writerGroupId, string $transportUri): void. PHP lets you declare fewer parameters if you only need the message.

  3. 03

    Run the loop

    Use run() for a dedicated worker process. For a custom event loop, call poll(int $timeoutMs) instead — see Subscriber & builder.

Unicast instead of multicast

Point the endpoint at a plain address/port to receive unicast UDP:

->listenUdp(endpoint: 'opc.udp://0.0.0.0:4840', readers: [$reader]);

JSON publishers

If the publisher emits JSON NetworkMessages (Part 14 §7.2) instead of UADP, flip the codec before listening:

SubscriberBuilder::create()
    ->useJson()
    ->onDataSetMessage($callback)
    ->listenUdp(endpoint: 'opc.udp://239.0.0.1:4840', readers: [$reader]);

Graceful shutdown

run() blocks. Wire stop() to a signal handler (pcntl_signal(SIGTERM, fn () => $subscriber->stop())) so the loop exits cleanly between polls.