PHPackages                             maringpcoder/nacos-sdk-php - 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. maringpcoder/nacos-sdk-php

ActiveLibrary[API Development](/categories/api)

maringpcoder/nacos-sdk-php
==========================

PHP SDK For Nacos

0133PHP

Since Sep 20Pushed 3y agoCompare

[ Source](https://github.com/maringpcoder/nacos-sdk-php)[ Packagist](https://packagist.org/packages/maringpcoder/nacos-sdk-php)[ RSS](/packages/maringpcoder-nacos-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Nacos-Sdk-PHP
=============

[](#nacos-sdk-php)

![license](https://camo.githubusercontent.com/01dc134d6da3895cd6eefe1d56c34de8cbe95bf3a7473f569d32dcf83676ac0b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f54696e7977616e2f6e61636f732d73646b2d706870)[![996.icu](https://camo.githubusercontent.com/ac8f294a80f65338db545230f1a881b9a382204a1f187c6ff40ee679d42d40ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b2d3939362e6963752d7265642e737667)](https://996.icu)![Build status](https://github.com/Tinywan/dnmp/workflows/CI/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/6da77cc942ed6569ca0d7062bfdd12661b2ea1fb5fd3dda4bc070f5d1b9bd6a2/687474703a2f2f706f7365722e707567782e6f72672f74696e7977616e2f6e61636f732d73646b2d7068702f76)](https://packagist.org/packages/tinywan/nacos-sdk-php)[![Total Downloads](https://camo.githubusercontent.com/379ac1e0d4f10a5ca23925f6c3a6ea8180b996f741cce74fd81e06d00edc8810/687474703a2f2f706f7365722e707567782e6f72672f74696e7977616e2f6e61636f732d73646b2d7068702f646f776e6c6f616473)](https://packagist.org/packages/tinywan/nacos-sdk-php)[![License](https://camo.githubusercontent.com/073b439811300ff18e28df11a95c0e3a632d6c2355e8f8c1f1fc907a8bc6063e/687474703a2f2f706f7365722e707567782e6f72672f74696e7977616e2f6e61636f732d73646b2d7068702f6c6963656e7365)](https://packagist.org/packages/tinywan/nacos-sdk-php)[![PHP Version Require](https://camo.githubusercontent.com/647dcedd202661a90e3cd341a71eb2be4327ff0bd3c7431ff8f2b6f05faf9f02/687474703a2f2f706f7365722e707567782e6f72672f74696e7977616e2f6e61636f732d73646b2d7068702f726571756972652f706870)](https://packagist.org/packages/tinywan/nacos-sdk-php)

Nacos-Sdk-PHP
-------------

[](#nacos-sdk-php-1)

Nacos-Sdk-PHP for PHP client allows you to access Nacos OpenAPI. [Open API Guide](https://nacos.io/en-us/docs/open-api.html)

Requirements
------------

[](#requirements)

- PHP ^7.0

Installation
------------

[](#installation)

```
composer require maringpcoder/nacos-sdk-php
```

Getting Started
---------------

[](#getting-started)

```
use Nacos\NacosClient;

$client = new NacosClient('localhost', 8848);
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$result = $client->getConfig($dataId, $group);
```

if `nacos.core.auth.enabled=true`

```
use Nacos\NacosClient;
use Nacos\NacosAuth;

$client = new NacosClient('localhost', 8848);

$auth = new NacosAuth($client);
$auth->login('nacos','nacos');
$token = $auth->getAccessToken();
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$client->setNamespace("01ae5458-c846-4440-88f4-ec0106c88f82");
$config = $client->getConfig("micro-service-conf", "dev", ["accessToken" => $auth->getAccessToken()]);
```

Use Namespace
-------------

[](#use-namespace)

```
use Nacos\NacosClient;

$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$namespace = 'c78ce19d-82d1-456a-8552-9a0db6c11d01';

$client = new NacosClient('localhost', 8848);
$client->setNamespace($namespace);
$result = $client->getConfig($dataId, $group);
```

Listener Config
---------------

[](#listener-config)

```
use Nacos\NacosClient;
use Nacos\Models\Config;

$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$namespace = 'c78ce19d-82d1-456a-8552-9a0db6c11d01';

$client = new NacosClient('localhost', 8848);
$client->setNamespace($namespace);
$client->setTimeout(3);
$content = $client->getConfig($dataId, $group);
$contentMd5 = md5($content);

$cache = new Config();
$cache->dataId = $dataId;
$cache->group = $group;
$cache->namespace = $namespace;
$cache->contentMd5 = $contentMd5;
$result = $client->listenConfig([$cache]);
if(!empty($result)) {
    $updateContent = $client->getConfig($dataId, $group);
    echo '[x] update content : ' . $updateContent, "\n";
} else {
    echo '[x] this is not update ', "\n";
}
```

Register an instance to the service
-----------------------------------

[](#register-an-instance-to-the-service)

```
use Nacos\NacosClient;
use Nacos\Models\Config;

$client = new NacosClient('localhost', 8848);

$serviceName  = 'NacosTaskService';
$instance = new ServiceInstance();
$instance->serviceName = $serviceName;
$instance->ip = '127.0.0.1';
$instance->port = 80;
$instance->healthy = true;
$instance->ephemeral = false;

$isSuccess = $client->createInstance($instance);
if(true === $isSuccess) {
    echo '[x] create service instance success ', "\n";
} else {
    echo '[x] create service instance fail ', "\n";
}
```

[![nacaos-regiter-service.png](./img/nacaos-regiter-service.png)](./img/nacaos-regiter-service.png)

API
---

[](#api)

### Request Options

[](#request-options)

- setNamespace
    - string $namespace
- setTimeout
    - int $timeout

### Config API

[](#config-api)

- getConfig
    - string $dataId
    - string $group = NacosClient::DEFAULT\_GROUP
- publishConfig
    - string $dataId
    - string $group
    - $content
- removeConfig
    - string $dataId
    - string $group = NacosClient::DEFAULT\_GROUP
- listenConfig
    - array $configs
    - int $timeout = 30

### Naming API

[](#naming-api)

- createInstance
    - ServiceInstance $instance
- deleteInstance
    - string $serviceName
    - string $ip
    - int $port
    - string $clusterName = null
    - string $namespaceId = null
- updateInstance
    - ServiceInstance $instance
- getInstanceList
    - string $serviceName
    - string $namespaceId = null
    - array $clusters = \[\]
    - bool $healthyOnly = false
- getInstance
    - string $serviceName
    - string $ip
    - int $port
    - string $namespaceId = null
    - string $cluster = null
    - bool $healthyOnly = false
- sendInstanceBeat
    - string $serviceName
    - BeatInfo $beat

PHPUnit Test
------------

[](#phpunit-test)

NacosClientTest

```
./vendor/bin/phpunit --bootstrap src/Nacos/NacosClient.php tests/NacosClientTest.php

```

- phpunit 调用命令行测试PHPUnit
- --bootstrap src/Nacos/NacosClient.php 指示PHPUnit命令行测试在测试之前执行 include src/Nacos/NacosClient.php
- tests/NacosClientTest.php 指示PHPUnit命令行测试要执行的测试 NacosClientTest 类声明在 tests/NacosClientTest.php
-

NacosConfig

```
./vendor/bin/phpunit --bootstrap src/Nacos/NacosConfig.php tests/NacosConfigTest.php

```

NacosNaming

```
./vendor/bin/phpunit --bootstrap src/Nacos/NacosNaming.php tests/NacosNamingTest.php

```

Other
-----

[](#other)

Docker Composer

```
docker run --rm --interactive --tty -v e:/GitHub/nacos-sdk-php:/app composer:1.10.16 install --ignore-platform-reqs

```

Git Tag

```
git push origin v0.0.42
// or push all
git push origin --tags

```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/020a17209e4579af619a54118836b63cf44cd9ecb48dbe4163ad31f144f1328f?d=identicon)[zhengdiao2001](/maintainers/zhengdiao2001)

---

Top Contributors

[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (74 commits)")[![zhengdiao](https://avatars.githubusercontent.com/u/11643859?v=4)](https://github.com/zhengdiao "zhengdiao (6 commits)")

### Embed Badge

![Health badge](/badges/maringpcoder-nacos-sdk-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

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

A PHP wrapper for Twilio's API

1.6k92.9M270](/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.1M452](/packages/google-gax)

PHPackages © 2026

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