OPC UA from PHP? Yes, with Zero C Extensions — Introducing php-opcua/opcua-client
A pure PHP library that implements the full OPC UA binary protocol stack — connect to PLCs, SCADA systems, and industrial IoT devices directly from Laravel, Symfony, or plain PHP.
Full article excerpt tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 130513) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Gianfrancesco Posted on Apr 28 OPC UA from PHP? Yes, with Zero C Extensions — Introducing php-opcua/opcua-client #php #iot #industrialautomation #laravel If you've ever tried to connect a PHP application to industrial machinery — a PLC, a SCADA system, a historian — you've probably hit a wall. The OPC UA standard is the lingua franca of industrial IoT, but most implementations assume you're writing in C++, Python, or .NET. PHP? Good luck finding anything that isn't a thin HTTP wrapper around a gateway you have to run separately. That changes with php-opcua/opcua-client. What Is OPC UA? OPC UA (Unified Architecture) is an industrial communication standard developed by the OPC Foundation. It lets software clients talk to sensors, PLCs, SCADA systems, historians, and IoT devices over a standardized protocol — with built-in security, data typing, discovery, and more. It's the backbone of Industry 4.0 and IIoT architectures worldwide. The protocol runs over TCP (binary encoding) and is notoriously complex to implement: it includes asymmetric and symmetric encryption, certificate management, session handling, subscriptions, historical queries, and a rich address space model. Why a Pure PHP Implementation? Most PHP projects that need OPC UA resort to one of: An HTTP REST gateway (adds a sidecar process, latency, and a point of failure) A COM bridge on Windows (commercial, not portable) Shelling out to a Python or Node.js script php-opcua/opcua-client is different. It implements the entire OPC UA binary protocol stack natively in PHP, with only ext-openssl as a runtime dependency. No FFI. No COM. No gateway. Just composer require and you're connecting to PLCs from your Laravel app. Quick Start composer require php-opcua/opcua-client Enter fullscreen mode Exit fullscreen mode use PhpOpcua\Client\ClientBuilder; $client = ClientBuilder::create() ->connect('opc.tcp://localhost:4840'); $status = $client->read('i=2259'); echo $status->getValue(); // 0 = Running $client->disconnect(); Enter fullscreen mode Exit fullscreen mode Three lines. No config files, no XML, no service containers. NodeId strings like 'i=2259', 'ns=2;i=1001', or 'ns=2;s=MyNode' are accepted everywhere. Invalid strings throw InvalidNodeIdException. Core Features in Practice Browse the Address Space $refs = $client->browse('i=85'); // Objects folder foreach ($refs as $ref) { echo "{$ref->displayName} ({$ref->nodeId})\n"; // => Server (ns=0;i=2253) // => MyPLC (ns=2;i=1000) } Enter fullscreen mode Exit fullscreen mode Read Multiple Values in One Round-Trip $results = $client->readMulti() ->node('i=2259')->value() ->node('ns=2;i=1001')->displayName() ->node('ns=2;s=Temperature')->value() ->execute(); foreach ($results as $dataValue) { echo $dataValue->getValue() . "\n"; } Enter fullscreen mode Exit fullscreen mode The fluent builder auto-batches requests transparently — one TCP round-trip regardless of how many nodes you chain. Write to a PLC use PhpOpcua\Client\Types\BuiltinType; // Auto-detect type (reads the node first, caches the result) $client->write('ns=2;i=1001', 42); // Explicit type $client->write('ns=2;i=1001', 42, BuiltinType::Int32); Enter fullscreen mode Exit…
This excerpt is published under fair use for community discussion. Read the full article at DEV Community.