PHPackages                             mimic/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. mimic/nacos

ActiveLibrary

mimic/nacos
===========

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

v1.0.1(4y ago)14MITPHP

Since Jun 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/shine96/nacos)[ Packagist](https://packagist.org/packages/mimic/nacos)[ RSS](/packages/mimic-nacos/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

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

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

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

### 特性

[](#特性)

1. 容错兜底
2. 容易上手
3. 技术支持，有问题可提交issue

### 开发计划

[](#开发计划)

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

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

[](#composer安装)

```
composer require mimic/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")  Contributions of any kind are welcome!

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Every ~0 days

Total

2

Last Release

1789d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a89fcb4dc96db20af5d0902088ff7bf68cc50a4ba5d9db16fb9a082380237f69?d=identicon)[shine96](/maintainers/shine96)

---

Top Contributors

[![shine96](https://avatars.githubusercontent.com/u/58157887?v=4)](https://github.com/shine96 "shine96 (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[google/cloud-core

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

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

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)

PHPackages © 2026

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