承接 percheetah/mdns-react 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

percheetah/mdns-react

Composer 安装命令:

composer require percheetah/mdns-react

包简介

Simple, async multicast DNS (mDNS) resolver for zeroconf networking, built on top of ReactPHP.

README 文档

README

CI status installs on Packagist

Simple, async multicast DNS (mDNS) resolver for zeroconf networking, built on top of ReactPHP.

Multicast DNS name resolution is commonly used as part of zeroconf networking. It is used by Mac OS X (Bonjour), many Linux distributions (Avahi) and quite a few other networking devices such as printers, camers etc. to resolve hostnames of your local LAN clients to IP addresses.

This library implements the mDNS protocol as defined in RFC 6762. Note that this protocol is related to, but independent of, DNS-Based Service Discovery (DNS-SD) as defined in RFC 6763.

Table of Contents

Note: This project is in beta stage! Feel free to report any issues you encounter.

Quickstart example

Once installed, you can use the following code to look up the address of a local domain name:

<?php

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

$factory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$resolver->resolve('hostname.local')->then(function ($ip) {
    echo 'Found: ' . $ip . PHP_EOL;
}, function (Exception $e) {
    echo 'Error: ' . $e->getMessage() . PHP_EOL;
});

See also the examples.

Usage

Factory

The Factory is responsible for creating your Resolver instance.

$factory = new Factory();

This class takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use for this object. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

createResolver()

The createResolver() method can be used to create a mDNS resolver instance that sends multicast DNS queries and waits for incoming unicast DNS responses. It returns a Resolver instance.

$resolver = $factory->createResolver();

Resolver

The Factory creates instances of the React\Dns\Resolver\Resolver class from the react/dns package.

While ReactPHP's normal DNS resolver uses unicast UDP messages (and TCP streams) to query a given nameserver, this resolver instance uses multicast UDP messages to query all reachable hosts in your network.

Promises

Sending queries is async (non-blocking), so you can actually send multiple DNS queries in parallel. The mDNS hosts will respond to each DNS query message with a DNS response message. The order is not guaranteed. Sending queries uses a Promise-based interface that makes it easy to react to when a query is fulfilled (i.e. either successfully resolved or rejected with an error):

$resolver->resolve($hostname)->then(
    function ($ip) {
        // IP successfully resolved
    },
    function (Exception $e) {
        // an error occurred while looking up the given hostname
    }
});

Please refer to the DNS documentation for more details.

Blocking

As stated above, this library provides you a powerful, async API by default.

If, however, you want to integrate this into your traditional, blocking environment, you should look into also using clue/reactphp-block.

The resulting blocking code could look something like this:

<?php

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

use Clue\React\Block;

$factory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$promise = $resolver->resolve('me.local');

try {
    $ip = Block\await($promise, $loop);
    // IP successfully resolved
} catch (Exception $e) {
    // an error occurred while performing the request
}

Similarly, you can also process multiple lookups concurrently and await an array of results:

$promises = array(
    $resolver->resolve('first.local'),
    $resolver->resolve('second.local'),
);

$ips = Block\awaitAll($promises, $loop);

Please refer to clue/reactphp-block for more details.

Install

The recommended way to install this library is through Composer. New to Composer?

composer require clue/mdns-react:~0.2.0

See also the CHANGELOG for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's highly recommended to use the latest supported PHP version for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

composer install

To run the test suite, go to the project root and run:

vendor/bin/phpunit

License

This project is released under the permissive MIT license.

Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

More

percheetah/mdns-react 适用场景与选型建议

percheetah/mdns-react 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 percheetah/mdns-react 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-12