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

ActiveLibrary[API Development](/categories/api)

lh4yp/nacos-v2
==============

阿里巴巴nacos配置中心php客户端（含授权）

098PHP

Since Jul 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lh4yp/php-nacos)[ Packagist](https://packagist.org/packages/lh4yp/nacos-v2)[ RSS](/packages/lh4yp-nacos-v2/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

阿里巴巴nacos配置中心-PHP客户端(新增授权逻辑)
============================

[](#阿里巴巴nacos配置中心-php客户端新增授权逻辑)

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

### 特性

[](#特性)

1. 容错兜底
2. 容易上手
3. 技术支持，有问题可加作者微信: suxiaolinKing
4. 添加curl鉴权功能

### 开发计划

[](#开发计划)

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

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

[](#composer安装)

```
composer require lh4yp/nacos-v2
```

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

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

定时1分钟拉取一次

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

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

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

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

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

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

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

```
Nacos::init(
    "http://127.0.0.1:8848/",
    "dev",
    "LARAVEL",
    "DEFAULT_GROUP",
    "USER_NAME",
    "PASSWORD",
    ""
)->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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/241fad873552b0df4c290ce6ee34e0ca3abe9dd933fbd3afdce32d0654a2a241?d=identicon)[lh4yp](/maintainers/lh4yp)

---

Top Contributors

[![lh4yp](https://avatars.githubusercontent.com/u/39228092?v=4)](https://github.com/lh4yp "lh4yp (9 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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