PHPackages                             zxyfaxcn/nacos - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zxyfaxcn/nacos

ActiveLibrary

zxyfaxcn/nacos
==============

nacos php sdk with hyperf framework

1.0.0(5y ago)0772Apache-2.0PHP

Since May 24Pushed 5y ago2 watchersCompare

[ Source](https://github.com/zxyfaxcn/nacos)[ Packagist](https://packagist.org/packages/zxyfaxcn/nacos)[ RSS](/packages/zxyfaxcn-nacos/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

### nacos

[](#nacos)

> Hyperf 框架下关于 Nacos 微服务的 php SDK

#### 安装

[](#安装)

```
composer require zxyfaxcn/nacos
```

#### 发布配置文件

[](#发布配置文件)

```
php bin/hyperf.php vendor:publish zxyfaxcn/nacos
```

#### 目录结构

[](#目录结构)

```
./src
├── Config   配置的自动更新
│   ├── FetchConfigProcess.php
│   ├── OnPipeMessageListener.php
│   └── PipeMessage.php
├── ConfigProvider.php   Hyperf扩展配置
├── Helper   辅助函数
│   └── func.php
├── Lib   Nacos Api 封装
│   ├── AbstractNacos.php
│   ├── NacosConfig.php
│   ├── NacosInstance.php
│   ├── NacosOperator.php
│   └── NacosService.php
├── Listener
│   ├── BootAppConfListener.php   启动时自动注册
│   └── OnShutdownListener.php   关闭服务时自动注销
├── Model   领域模型
│   ├── AbstractModel.php
│   ├── ConfigModel.php
│   ├── InstanceModel.php
│   └── ServiceModel.php
├── Process   心跳
│   └── InstanceBeatProcess.php
├── ThisInstance.php   当前节点
├── ThisService.php   当前服务
└── Util
    ├── Guzzle.php
    └── RemoteConfig.php
```

### 服务与实例

[](#服务与实例)

`BootAppConfListener.php` 将在系统启动完成时自动完成`实例注册`, `服务注册`

如果需要在服务下线时自动注销服务, 请增加如下配置, 以监听 `Shutdown` 事件

```
// config/autoload/server.php

return [
    // ...other
    'callbacks' => [
        // ...other
        SwooleEvent::ON_SHUTDOWN => [Hyperf\Framework\Bootstrap\ShutdownCallback::class, 'onShutdown']
    ]
];
```

#### 获取当前实例

[](#获取当前实例)

```
$instance = new ThisInstance();
```

#### 获取当前服务

[](#获取当前服务)

```
$service = new ThisService();
```

#### 获取一个服务的最优节点

[](#获取一个服务的最优节点)

```
$instance = make(NacosInstance::class);

$service = new ServiceModel([
    'serviceName' => 'hyperf',
    'groupName' => 'api',
    'namespaceId' => '5ce9d1c1-6732-4ccc-ae1f-5139af86a845'
]);

$optimal = $instance->getOptimal($service);
```

### 配置中心

[](#配置中心)

`BootAppConfListener.php` 系统启动时将拉取远程配置, 并合入`hyperf` 的 `Config`

`FetchConfigProcess.php` 自定义进程将监听配置, 若有更新将发送`PipeMessage` 到各服务`worker`进程, 并合入当前进程的 `Config`

如果服务如下配置

```
// config/autoload/nacos.php

return [
    'enable' => true, // 是否开启自动注册 默认false
    'deleteServiceWhenShutdown' => true, // 是否开启自动注销 默认false
    'host' => '127.0.0.1',
    'port' => '8848',
    // 服务配置 serviceName, groupName, namespaceId
    // protectThreshold, metadata, selector
    'service' => [
        'serviceName' => 'hyperf',
        'groupName' => 'api',
        'namespaceId' => 'namespace_id',
        'protectThreshold' => 0.5,
    ],
    // 节点配置 serviceName, groupName, weight, enabled,
    // healthy, metadata, clusterName, namespaceId, ephemeral
    'client' => [
        'namespaceId' => 'namespace_id', // 注意此处必须和service保持一致
        'serviceName' => 'hyperf',
        'groupName' => 'DEFAULT',
        'weight' => 80,
        'enabled' => true,
        'healthy' => true,
        'cluster' => 'DEFAULT',
        'ephemeral' => true,
        'beatEnable' => true,// 心跳
        'beatInterval' => 5,// s
    ],
    // 配置刷新
    'configReloadEnable' => false,
    'configReloadInterval' => 3,// 间隔 s
    // 远程配置合并节点, 默认 config 根节点
    'configAppendNode' => 'nacos_conf',
    'listenerConfig' => [
        // 配置项 dataId, group, tenant, type, content
        [
            'dataId' => 'hyperf-service-config',
            'group' => 'DEFAULT_GROUP',
        ],
        [
            'dataId' => 'hyperf-service-config-yml',
            'group' => 'DEFAULT_GROUP',
            'type' => 'yml',
        ],
    ],
];
```

系统将自动监听`listenerConfig` 中的配置, 并将其合并入`hyperf Config` 对象的指定(`configAppendNode`) 节点, 可以用`config('nacos_conf.***')` 获取, 若没有配置 `configAppendNode` 项, 将会并入 `Config` 对象根节点.

#### 依赖扩展

[](#依赖扩展)

`ext-json`, `ext-yaml`, `ext-simplexml`, `ext-libxml`

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2184d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4cbf644c1c87edf82dc04fca6167682dae6bf5ce75ef83bd833d17c3eff5eaac?d=identicon)[zxyfaxcn](/maintainers/zxyfaxcn)

---

Top Contributors

[![zxyfaxcn](https://avatars.githubusercontent.com/u/2535215?v=4)](https://github.com/zxyfaxcn "zxyfaxcn (16 commits)")

### Embed Badge

![Health badge](/badges/zxyfaxcn-nacos/health.svg)

```
[![Health](https://phpackages.com/badges/zxyfaxcn-nacos/health.svg)](https://phpackages.com/packages/zxyfaxcn-nacos)
```

###  Alternatives

[mineadmin/mineadmin

Quickly build a background management system for web applications

1.2k2.0k](/packages/mineadmin-mineadmin)[hyperf/hyperf-skeleton

A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.

301187.4k](/packages/hyperf-hyperf-skeleton)[hyperf/swow-skeleton

A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.

514.5k](/packages/hyperf-swow-skeleton)[xmo/mine-core

mineadmin core package

1684.2k1](/packages/xmo-mine-core)[hyperf/odin

425.9k](/packages/hyperf-odin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
