PHPackages                             ze/nacos-connect - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ze/nacos-connect

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ze/nacos-connect
================

阿里巴巴nacos配置中心php客户端

v2.0.2(4y ago)06MITPHP

Since Mar 29Pushed 4y agoCompare

[ Source](https://github.com/zyz954489346/php-nacos)[ Packagist](https://packagist.org/packages/ze/nacos-connect)[ RSS](/packages/ze-nacos-connect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (18)Used By (0)

阿里巴巴nacos配置中心-PHP客户端
====================

[](#阿里巴巴nacos配置中心-php客户端)

> 项目基于[php-nacos](https://github.com/neatlife/php-nacos)修改，由于原项目维护进度缓慢，故在原有基础上做依赖更新。

[Nacos配置中心](https://github.com/alibaba/nacos)的PHP客户端，更多关于Nacos配置中心的介绍，可以查看[Nacos配置中心Wiki](https://github.com/alibaba/nacos/wiki)。

### 特性

[](#特性)

1. 容错兜底
2. 容易上手
3. 技术支持，有问题可加作者微信: suxiaolinKing

### 开发计划

[](#开发计划)

- 增强容错机制
- [实现服务发现](NAMING.md)
- [Laravel框架集成](https://juejin.im/post/5ccf645b6fb9a032435dba16)
- Dummy模式(本地开发不走配置中心)
- Yii框架集成
- ThinkPHP框架集成
- Symfony框架集成

composer安装
----------

[](#composer安装)

```
composer require alibaba/nacos
```

使用crontab拉取配置文件
---------------

[](#使用crontab拉取配置文件)

定时1分钟拉取一次

```
*/1 */1 * * * php path/to/cron.php
```

```
# cron.php
Nacos::init(
    "http://127.0.0.1:8848/",
    "dev",
    "LARAVEL",
    "DEFAULT_GROUP",
    ""
)->runOnce();
```

拉取到的配置文件路径：当前工作目录/nacos/config/dev\_nacos/snapshot/LARAVEL

配置文件保存的工作目录可以通过下面命令修改

```
NacosConfig::setSnapshotPath("指定存放配置文件的目录路径");
```

长轮询拉取配置文件
---------

[](#长轮询拉取配置文件)

```
Nacos::init(
    "http://127.0.0.1:8848/",
    "dev",
    "LARAVEL",
    "DEFAULT_GROUP",
    ""
)->listener();
```

事件监听器
-----

[](#事件监听器)

```
GetConfigRequestErrorListener::add(function($config) {
    if (!$config->getConfig()) {
        echo "获取配置异常, 配置为空，下面进行自定义逻辑处理" . PHP_EOL;
        // 设置是否修改配置文件内容，如果修改成true，这里设置的配置文件内容将是最终获取到的配置文件
        $config->setChanged(true);
        $config->setConfig("hello");
    }
});
```

配置兜底方案
------

[](#配置兜底方案)

将兜底的配置文件放入下面的路径里

如果有给$tenant设置值，文件路径这样计算

工作目录/nacos/config/{$env}\_nacos/config-data-{$tenant}/{$dataId}

否则

工作目录/nacos/config/{$env}\_nacos/config-data/{$dataId}

nacos会在无法从配置中心查询配置文件时将读取上面的配置文件

Dummy模式(本地开发不走配置中心)
-------------------

[](#dummy模式本地开发不走配置中心)

配置环境变量NACOS\_ENV=local再启动项目

```
export NACOS_ENV=local
```

贡献者 ✨
-----

[](#贡献者-)

Thanks goes to these wonderful people:

   [![](https://avatars0.githubusercontent.com/u/4350262?s=88&v=4)
**fatrbaby**](https://github.com/fatrbaby)
 [📖](https://github.com/neatlife/php-nacos/commits?author=fatrbaby "Documentation")   [![](https://avatars3.githubusercontent.com/u/18006395?s=88&v=4)
**TELstatic**](https://github.com/TELstatic)
 [📖](https://github.com/neatlife/php-nacos/commits?author=TELstatic "Documentation")   [![](https://avatars3.githubusercontent.com/u/12997869?s=88&v=4)
**wujunze**](https://github.com/wujunze)
 [📖](https://github.com/neatlife/php-nacos/commits?author=wujunze "Documentation")   [![](https://avatars.githubusercontent.com/u/17122751?v=4)
**ifcute**](https://github.com/ifcute)
 [📖](https://github.com/neatlife/php-nacos/commits?author=ifcute "Documentation")   [![](https://avatars.githubusercontent.com/u/1926185?v=4)
**RobberPhex**](https://github.com/RobberPhex)
 [📖](https://github.com/neatlife/php-nacos/commits?author=RobberPhex "Documentation")  Contributions of any kind are welcome!

感谢nacos团队赠送的纪念杯
---------------

[](#感谢nacos团队赠送的纪念杯)

[![](docs/img/nacos-mug-1.jpg)](docs/img/nacos-mug-1.jpg)[![](docs/img/nacos-mug-2.jpg)](docs/img/nacos-mug-2.jpg)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 69.4% 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

Every ~56 days

Recently: every ~183 days

Total

16

Last Release

1760d ago

Major Versions

v0.0.11 → v1.0.02019-09-03

v1.0.1 → v2.0.12021-07-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/6347bd82fe503e6d208d8899cec05533667148d3f6659e91dbb82ea92dd2446e?d=identicon)[zyz954489346](/maintainers/zyz954489346)

---

Top Contributors

[![neatlife](https://avatars.githubusercontent.com/u/4076198?v=4)](https://github.com/neatlife "neatlife (25 commits)")[![zyz954489346](https://avatars.githubusercontent.com/u/23162012?v=4)](https://github.com/zyz954489346 "zyz954489346 (5 commits)")[![DeadlineSurvivor](https://avatars.githubusercontent.com/u/18006395?v=4)](https://github.com/DeadlineSurvivor "DeadlineSurvivor (2 commits)")[![fatrbaby](https://avatars.githubusercontent.com/u/4350262?v=4)](https://github.com/fatrbaby "fatrbaby (2 commits)")[![ifcute](https://avatars.githubusercontent.com/u/17122751?v=4)](https://github.com/ifcute "ifcute (1 commits)")[![wujunze](https://avatars.githubusercontent.com/u/12997869?v=4)](https://github.com/wujunze "wujunze (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[googleads/google-ads-php

Google Ads API client for PHP

3497.6M9](/packages/googleads-google-ads-php)[alibaba/nacos

阿里巴巴nacos配置中心php客户端

19340.8k1](/packages/alibaba-nacos)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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