OPC UA in Pure PHP: Introducing the PHP-Opcua Project

gianfriaur2 pts0 comments

OPC UA in Pure PHP: Introducing the php-opcua Project · PHP Opc Ua

Menu

Home

Documentation

Blog

About

Sign in

OPC UA (Open Platform Communications Unified Architecture) is the vendor-neutral protocol that PLCs, SCADA systems, sensors and historians use to expose data and methods. If you've ever needed production data in a web application, OPC UA is almost certainly where that data lives.\nUntil now, a PHP developer had three options, all bad: compile and maintain a C\/C++ extension, stand up an HTTP gateway in another language and poll it, or simply switch language. Each option adds a moving part between your application and the machine \u2014 one more thing to deploy, secure and debug.\nphp-opcua removes the moving part. The whole protocol stack \u2014 binary encoding, secure channels, sessions \u2014 is implemented in PHP itself, based on the OPC UA specification. If your server runs PHP 8.2+, it can talk to the factory floor natively.\nWhat ships today\nThe ecosystem is split into focused packages, so you only install what you use:\n\n\n\nPackage\nWhat it does\n\n\n\n\nopcua-client\nThe core: browse, read, write, method calls, subscriptions, events, alarms, history read. 10 security policies (RSA and experimental ECC), full certificate management.\n\n\nopcua-cli\nBrowse, watch and write from the terminal; generate typed PHP classes from NodeSet2.xml files.\n\n\nopcua-session-manager\nA ReactPHP daemon that keeps sessions alive across PHP requests (~150 ms cold connect \u2192 ~5 ms per request).\n\n\nlaravel-opcua\nFacade, .env configuration, named connections, Artisan command for the session-manager daemon.\n\n\nsymfony-opcua\nSymfony bundle: autowireable OpcuaManager, YAML semantic configuration, Monolog channels, bin\/console opcua:session. Symfony 6.4 LTS and 7.x.\n\n\nopcua-client-ext-*\nTransport and connectivity extensions: Reverse Connect for servers behind NAT\/firewalls, opc.https over port 443, and a PubSub subscriber for UDP telemetry.\n\n\n\nOn top of the core, opcua-client-nodeset ships pre-generated typed classes for 51 OPC Foundation companion specifications \u2014 DI, Robotics, MachineTool, PackML, ISA-95 and more \u2014 so $robot->getAxes() is a real, autocompleted method call instead of a hand-built node lookup.\n\nRead your first value in five minutes\nYou'll need a reachable OPC UA server. If you don't have a PLC on your desk, any public demo server or a local simulator works the same way.\n\n \n \n \n 01\n \n Install the client\n \n One Composer package, no extensions to compile.\ncomposer require php-opcua\/opcua-client\n\n\n \n\n\n \n 02\n \n Connect to the server\n \n Point the builder at the endpoint URL. opc.tcp:\/\/ is OPC UA's binary transport \u2014 the fastest and most widely supported.\nuse PhpOpcua\\Client\\ClientBuilder;\n\n$client = ClientBuilder::create()\n ->connect('opc.tcp:\/\/192.168.1.10:4840');\n\n\n \n\n\n \n 03\n \n Read a node\n \n Every piece of data in an OPC UA server is a node, addressed by a NodeId \u2014 a namespace plus an identifier, like ns=2;s=Temperature.\n$temp = $client->read('ns=2;s=Temperature');\n\/\/ 23.7 \u2014 straight from the factory floor\n\n\n \n\n\n\nThe same read, in whichever flavour fits your stack:\n\n \n \n Plain PHP\n Laravel\n CLI\n \n\n \n {\n copied = true;\n setTimeout(() => { copied = false; }, 1500);\n };\n if (navigator.clipboard && window.isSecureContext) {\n navigator.clipboard.writeText(text).then(done).catch((err) => {\n console.error('tabs: clipboard.writeText failed', err);\n });\n } else {\n const ta = document.createElement('textarea');\n ta.value = text;\n ta.setAttribute('readonly', '');\n ta.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0';\n document.body.appendChild(ta);\n ta.select();\n try { document.execCommand('copy'); done(); }\n catch (err) { console.error('tabs: execCommand fallback failed', err); }\n finally { ta.remove(); }\n }\n \"\n :aria-label=\"copied ? 'Code copied' : 'Copy code'\"\n :class=\"copied ? '!opacity-100 text-emerald-300 ring-emerald-400\/30' : ''\"\n class=\"shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 inline-flex items-center gap-1.5 rounded-md bg-zinc-950\/80 backdrop-blur-sm ring-1 ring-violet-400\/20 px-2 py-1 text-[10px] font-mono uppercase tracking-[0.18em] text-zinc-300 hover:text-zinc-100 hover:bg-zinc-900 transition-all duration-150 focus:outline-none focus-visible:ring-2 cursor-pointer\"\n >\n \n \n \n \n \n \n Copy\n \n \n\n \n \n \n \n \n \n \n \n \n \n \n PHP\n \n read.php\n \n \n\n \n {\n copied = true;\n setTimeout(() => { copied = false; }, 1500);\n };\n if (navigator.clipboard && window.isSecureContext) {\n navigator.clipboard.writeText(text).then(done).catch((err) => {\n console.error('code-block: clipboard.writeText failed', err);\n });\n } else {\n const ta = document.createElement('textarea');\n ta.value = text;\n ta.setAttribute('readonly', '');\n ta.style.cssText =...

opcua u2014 client text copied read

Related Articles