skydiablo/koap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

skydiablo/koap

Composer 安装命令:

composer require skydiablo/koap

包简介

ReactPHP-based async client library for communicating with Keymile MileGate MSAN devices using the KOAP (Keymile Object Access Protocol) over the MTP (Message Transport Protocol) framing layer.

README 文档

README

ReactPHP-based async client library for communicating with Keymile MileGate MSAN devices using the KOAP (Keymile Object Access Protocol) over the MTP (Message Transport Protocol) framing layer.

Requirements

  • PHP 8.4+
  • ext-dom
  • ext-zlib

Installation

composer require skydiablo/koap

Quick Start

<?php

use SkyDiablo\Keymile\Koap\KoapClient;
use function React\Async\await;

require __DIR__ . '/vendor/autoload.php';

$client = new KoapClient('192.168.1.1', 5556, 'admin', 'secret');
$connection = await($client->connect());

// Discover the managed object tree
$root = await($connection->discover('/'));
echo sprintf("Connected to: %s (%s)\n", $root->moName, $root->moType);

// Read a property
$label = await($connection->get('/unit-1/port-1', 'main', 'Label'));
echo sprintf("Label: %s\n", $label['label']['user'] ?? '(empty)');

// Write a property
await($connection->set('/unit-1/port-1', 'main', 'Label', [
    'label' => [
        'user' => 'My Port',
        'service' => 'DSL',
        'description' => 'Customer line',
    ],
]));

$connection->close();

Architecture

The library is built in four layers:

MTP Transport Layer

The MileGate uses a proprietary binary framing protocol called MTP (Message Transport Protocol) on TCP port 5556. The MtpTransport handles the complete protocol stack:

Wire Format:

[2B magic: 0x0001] [2B payload length (BE)] [13B sub-header] [payload] [2B terminator: 0x0000]

Connection Flow:

  1. TCP connect to port 5556
  2. Init handshake (initrequest / initresponse) — negotiates MTP version
  3. Login (login_req / login_resp) — authenticates with SHA-1 hashed password
  4. KOAP request/response exchange
  5. Keepalive every ~5 seconds (MTP keepalive text message)

Message Types:

Type Hex Description
Init 0x01/0x81 Version negotiation
Login 0x02/0x82 Authentication
KOAP 0x04/0x84 XML request/response
Keepalive 0x10/0x90 Connection heartbeat

Compression: Server KOAP responses may be zlib-compressed (indicated by compression flag 0x02 in the sub-header). The library handles decompression transparently.

Message Layer

Handles serialization/deserialization of KOAP XML messages:

<!-- Request -->
<request version="1" seq="3" destAddr="/">
  <mdomain id="main">
    <operation seq="1" name="getDiscover" forced="true"/>
  </mdomain>
</request>

<!-- Response -->
<response version="1" seq="3" destAddr="/">
  <mdomain id="main">
    <operation seq="1" name="getDiscover">
      <execution status="success"/>
      <info>
        <motype>shelf</motype>
        <moname>MileGate 2300</moname>
        <!-- ... -->
      </info>
    </operation>
  </mdomain>
</response>

Client Layer

KoapClient creates connections with automatic MTP handshake, Connection provides the high-level API:

  • discover(string $destAddr, string $mDomain = 'main') — Explore the managed object tree (optional domain, e.g. main, cfgm, status)
  • get(string $destAddr, string $mDomain, string $operationName) — Read a property
  • set(string $destAddr, string $mDomain, string $operationName, array $payload) — Write a property
  • execute(string $destAddr, string $mDomain, string $operationName, array $payload) — Raw request/response
  • close() — Close the connection
  • isConnected() — Check if the connection is still active

Custom Transport

You can inject a custom TransportInterface to bypass the MTP layer:

use SkyDiablo\Keymile\Koap\KoapClient;

$client = new KoapClient('host', transport: $myCustomTransport);

The legacy TcpTransport with pluggable frame parsers (RawXmlFrameParser, NullTerminatedFrameParser, LengthPrefixedFrameParser) is still available for testing or non-standard setups.

Development

# Install dependencies
composer install

# Run tests
composer test

# Run static analysis (level 8)
composer analyse

License

MIT

skydiablo/koap 适用场景与选型建议

skydiablo/koap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-04