PHPackages                             zengonly/php-alibaba-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. [API Development](/categories/api)
4. /
5. zengonly/php-alibaba-nacos

ActiveLibrary[API Development](/categories/api)

zengonly/php-alibaba-nacos
==========================

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

v2.0.3(4y ago)0291MITPHP

Since Mar 29Pushed 4y agoCompare

[ Source](https://github.com/zengonly/php-nacos)[ Packagist](https://packagist.org/packages/zengonly/php-alibaba-nacos)[ RSS](/packages/zengonly-php-alibaba-nacos/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (3)Versions (19)Used By (0)

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

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

说明
--

[](#说明)

forked from neatlife/php-nacos，感谢作者提供的扩展

- 因该扩展不支持 Nacos 的认证功能，对扩展进行了修改，在发起请求时携带 accessToken
- @see
- todo accessToken 写入缓存

[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

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 73.5% 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 ~65 days

Recently: every ~223 days

Total

17

Last Release

1545d 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/313c601144fa9870e7b32ec21210203180fdf03f2f5501478057a675dbaf5107?d=identicon)[zengonly](/maintainers/zengonly)

---

Top Contributors

[![neatlife](https://avatars.githubusercontent.com/u/4076198?v=4)](https://github.com/neatlife "neatlife (25 commits)")[![ziqingba](https://avatars.githubusercontent.com/u/48835441?v=4)](https://github.com/ziqingba "ziqingba (3 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/zengonly-php-alibaba-nacos/health.svg)

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

###  Alternatives

[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[zepgram/module-rest

Technical module to industrialize API REST call with dependency injection pattern using Guzzle library

1326.2k](/packages/zepgram-module-rest)

PHPackages © 2026

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