定制 techdock/opcua 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

techdock/opcua

Composer 安装命令:

composer require techdock/opcua

包简介

Modern OPC UA Client for PHP 8.4+ - PHP implementation based on OPC Foundation UA-.NETStandard architecture

README 文档

README

CI Security PHP Version License

Modern, production-ready OPC UA (Unified Architecture) client library for PHP 8.4+. This library is a PHP implementation of OPC UA client functionality based on the architecture and design of the OPC Foundation UA-.NETStandard implementation. While maintaining wire-protocol compatibility and following the same design patterns, this is an independent implementation adapted for PHP 8.4+ with full type safety and modern language features.

Features

  • Complete OPC UA Client Implementation

    • Binary protocol (opc.tcp://) with full UA services
    • Secure channel with encryption (Basic256Sha256)
    • Session management with automatic reconnection
    • Certificate-based authentication
  • High-Level API

    • Fluent ClientBuilder for easy configuration
    • Browse address space with filtering
    • Read/write nodes with type safety
    • Subscriptions and monitored items
    • Event monitoring and alarms
  • Performance Optimizations

    • LRU caching for node metadata
    • Automatic batch splitting for large operations
    • Server capability detection
    • Connection pooling ready
  • Production Ready

    • PSR-3 logging integration
    • Comprehensive error handling
    • Type-safe throughout (PHP 8.4 strict types)
    • PHPStan level 9 compliant
    • Extensive test coverage

Quick Start

Installation

composer require techdock/opcua

Basic Usage

<?php

use TechDock\OpcUa\Client\ClientBuilder;
use TechDock\OpcUa\Core\Types\NodeId;

// Connect to server
$client = ClientBuilder::create()
    ->endpoint('opc.tcp://localhost:4840')
    ->withAnonymousAuth()
    ->build();

// Read a value
$serverTime = $client->session->read([NodeId::numeric(0, 2258)])[0];
echo "Server time: {$serverTime->value}\n";

// Browse nodes
$objectsFolder = NodeId::numeric(0, 85);
$references = $client->browser->browse($objectsFolder);

foreach ($references as $ref) {
    echo "- {$ref->displayName->text}\n";
}

// Clean up
$client->disconnect();

With Performance Features

$client = ClientBuilder::create()
    ->endpoint('opc.tcp://production-server:4840')
    ->application('My App', 'urn:mycompany:app')
    ->withUsernameAuth('operator', 'password')
    ->withCache(maxSize: 5000, ttl: 600.0)  // 10min cache
    ->withAutoBatching()                     // Auto-split large requests
    ->operationTimeout(60000)                // 60s timeout
    ->build();

Monitoring Data Changes

// Create subscription
$subscription = $client->session->createSubscription(
    publishingInterval: 1000.0,  // 1 second
);

// Monitor a node
$nodeId = NodeId::numeric(2, 1001);
$subscription->createMonitoredItem(
    nodeId: $nodeId,
    samplingInterval: 500.0,
    callback: function ($value, $timestamp) {
        echo "Value changed: {$value} at {$timestamp}\n";
    }
);

// Process notifications
while (true) {
    $subscription->publishAsync();
    usleep(100000); // 100ms
}

Documentation

Requirements

  • PHP 8.4 or higher
  • ext-sockets - Socket communication
  • OpenSSL support - For secure connections

Supported Features

Feature Status
TCP Binary Protocol ✅ Full
Secure Channel ✅ Basic256Sha256, None
Session Management ✅ Create, Activate, Close
Browse Services ✅ Full with continuation
Read/Write Services ✅ Multiple nodes
Subscriptions ✅ Data change, Events
Method Calls ✅ Full support
Historical Data ✅ ReadRaw, ReadProcessed
Type System ✅ Built-in + Custom structures
Certificate Auth ✅ X.509 certificates
Username Auth ✅ Username/password
Anonymous Auth ✅ Full support

Architecture

┌─────────────────────────────────────────┐
│         ClientBuilder (Fluent API)      │
├─────────────────────────────────────────┤
│  ConnectedClient                        │
│  ├─ Session (Service Calls)             │
│  ├─ Browser (Address Space)             │
│  └─ Cache (Optional)                    │
├─────────────────────────────────────────┤
│  Core Protocol Layer                    │
│  ├─ SecureChannel (Encryption)          │
│  ├─ BinaryEncoder/Decoder               │
│  └─ TcpConnection                       │
└─────────────────────────────────────────┘

Testing

# Run all tests
composer test

# Run with coverage
composer test-coverage

# Static analysis
composer analyse

# Code style
composer cs-check
composer cs-fix

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Security

For security vulnerabilities, please see SECURITY.md.

License

This project is licensed under the MIT License - see LICENSE file for details.

For complete attribution and licensing information, see NOTICE.

Credits

Developed by TechDock

Attribution

This library is a PHP implementation of OPC UA client functionality based on the architecture and design of the OPC Foundation UA-.NETStandard implementation. The original C#/.NET implementation provides the architectural foundation and design patterns for this PHP adaptation.

Original Project:

  • Repository: OPCFoundation/UA-.NETStandard
  • License: Dual-license (RCL for OPC Foundation members, GPL 2.0 for non-members)
  • Copyright: OPC Foundation

This PHP Implementation:

  • Scope: Client-only implementation (no server functionality)
  • Approach: Independent implementation following the same architectural patterns
  • Protocol: 100% wire-compatible with OPC UA binary protocol specification
  • Code: Adapted to PHP 8.4+ idioms, type system, and modern language features
  • Size: Approximately 35-40% of the .NET core stack code volume
  • License: MIT License (as an independent implementation)

Key Differences:

  • Client-only (UA-.NETStandard includes both client and server)
  • Hand-written message classes (vs. code-generated from XML schemas)
  • Focused on core client features (Browse, Read, Write, Subscribe, Call)
  • PHP-native approach using readonly classes, union types, and match expressions

We are deeply grateful to the OPC Foundation and the UA-.NETStandard contributors for their excellent reference implementation that made this PHP client possible.

Special thanks to:

  • The OPC Foundation for the OPC UA specification and reference implementations
  • The UA-.NETStandard development team for their well-architected codebase
  • All contributors to open-source OPC UA projects

See NOTICE for complete attribution and licensing details.

Resources

Support

techdock/opcua 适用场景与选型建议

techdock/opcua 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 356 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「automation」 「plc」 「iot」 「opcua」 「opc-ua」 「industrial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 techdock/opcua 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 techdock/opcua 我们能提供哪些服务?
定制开发 / 二次开发

基于 techdock/opcua 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 356
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 34
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-08