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

ActiveLibrary[API Development](/categories/api)

yurunsoft/nacos-php
===================

Nacos PHP client, which also supports Swoole Coroutine

v1.0.5(1y ago)166.0k41Apache-2.0PHPPHP &gt;=7.4

Since Jul 8Pushed 1y ago1 watchersCompare

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

READMEChangelog (6)Dependencies (5)Versions (8)Used By (1)

nacos-php
=========

[](#nacos-php)

[![Latest Version](https://camo.githubusercontent.com/f589594d5b998b99e1cf96951c195b055cf0dcf26156f205f6d4c14b47922fca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f797572756e736f66742f6e61636f732d7068702e737667)](https://packagist.org/packages/yurunsoft/nacos-php)[![GitHub Workflow Status (branch)](https://camo.githubusercontent.com/76ee44cbe27c6853274be25acf11742f2392eef9f6f5c18945fb00bb97e7c159/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f797572756e736f66742f6e61636f732d7068702f746573742f6d6173746572)](https://camo.githubusercontent.com/76ee44cbe27c6853274be25acf11742f2392eef9f6f5c18945fb00bb97e7c159/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f797572756e736f66742f6e61636f732d7068702f746573742f6d6173746572)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/046f897c88711f3a7eee1f3ec540eb9b7bf0eeb755d67e92e6093761f0b2f12a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e342e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![License](https://camo.githubusercontent.com/007ed3b9fd2ad6f7741034798e7e66a2c1f763ad9fbcc3a46435621c041c691c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865322d627269676874677265656e2e737667)](https://github.com/yurunsoft/nacos-php/blob/master/LICENSE)

**English** | [中文](README_CN.md)

Nacos php sdk for Go client allows you to access Nacos service, it supports service discovery and dynamic configuration.

Request and response data are all strongly typed and IDE friendly.

Complete test cases and support for Swoole Coroutine.

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

[](#requirements)

Supported PHP version over 7.4

Supported Swoole version over 4.4

Supported Nacos version over 1.x

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

[](#installation)

Use Composer to install SDK：

`composer require yurunsoft/nacos-php`

Quick Examples
--------------

[](#quick-examples)

### Client

[](#client)

```
use Yurun\Nacos\Client;
use Yurun\Nacos\ClientConfig;

// The parameters of ClientConfig are all optional, the ones shown below are the default values
// You can write only the configuration items you want to modify
$config = new ClientConfig([
    'host'                => '127.0.0.1',
    'port'                => 8848,
    'prefix'              => '/',
    'username'            => '',
    'password'            => '',
    'timeout'             => 60000, // Network request timeout time, in milliseconds
    'ssl'                 => false, // Whether to use ssl(https) requests
    'authorizationBearer' => false, // Whether to use the request header Authorization: Bearer {accessToken} to pass Token, older versions of Nacos need to be set to true
    'maxConnections'      => 16, // Connection pool max connections
    'poolWaitTimeout'     => 30, // Connection pool wait timeout when get connection, in seconds
    // Custom configuration processor to convert string configuration values to arbitrary types (e.g. arrays), which can override the default processing
    'configParser'        => [
        // type Name => callback(string value): mixed
        'json' => static fn (string $value): array => json_decode($value, true),
    ],
]);
// Instantiating the client, Not required
$client = new Client($config);

// Enable log, Support PSR-3
$logger = new \Monolog\Logger();
$client = new Client($config, $logger);

// Reopening the client, you can execute the first execution in the Swoole worker, process
$client->reopen();
```

### Providers

[](#providers)

```
// Get provider from client

$auth = $client->auth;
$config = $client->config;
$namespace = $client->namespace;
$instance = $client->instance;
$service = $client->service;
$operator = $client->operator;
```

### Dynamic configuration

[](#dynamic-configuration)

#### Get config

[](#get-config)

```
$value = $client->config->get('dataId', 'group');
```

#### Get parsed config

[](#get-parsed-config)

> Support json, xml, yaml (Required: yaml extension) Nacos &gt;= 1.4

```
$client->config->set('dataId', 'group', json_encode(['id' => 19260817]), 'json');
$value = $client->config->getParsedConfig('dataId', 'group', '', $type);

// output：
// array(1) {
//   ["id"]=>
//   int(19260817)
// }
var_dump($value);

var_dump($type); // json
```

#### Set config

[](#set-config)

```
$client->config->set('dataId', 'group', 'value');
```

#### Delete config

[](#delete-config)

```
$client->config->delete('dataId', 'group', 'value');
```

#### Listen config

[](#listen-config)

#### Config listener

[](#config-listener)

```
use Yurun\Nacos\Provider\Config\ConfigListener;
use Yurun\Nacos\Provider\Config\Model\ListenerConfig;

// Get config listener
$listenerConfig = new ListenerConfig([
    'timeout'  => 30000, // The config listener long polling timeout, in milliseconds. The result is returned immediately when the value is 0.
    'failedWaitTime' => 3000, // Waiting time to retry after failure, in milliseconds
    'savePath' => '', // Config save path, default is empty and not saved to file
    'fileCacheTime' => 0, // The file cache time, defaulted to 0, is not affected by caching, and this configuration only affects pull operations.
]);
$listener = $client->config->getConfigListener($listenerConfig);

$dataId = 'dataId';
$groupId = 'groupId';
$tenant = '';

// Add listening item
$listener->addListener($dataId, $groupId, $tenant);
// Add listening item with callback
$listener->addListener($dataId, $groupId, $tenant, function (\ConfigListener $listener, string $dataId, string $group, string $tenant) {
    // $listener->stop();
});

// Pull configuration for all listeners (not required)
// Forced pull, not affected by fileCacheTime
$listener->pull();
$listener->pull(true);
// Pull, affected by fileCacheTime
$listener->pull(false);

// Manually perform a poll
$listener->polling(); // The timeout in the ListenerConfig is used as the timeout time.
$listener->polling(30000); // Specify the timeout period
$listener->polling(0); // Return results immediately

// Start the polling listener and do not continue with the following statements until you stop
$listener->start();

// To get the configuration cache from the listener, you need to call it in another coroutine
$value = $listener->get($dataId, $groupId, $tenant, $type);
var_dump($type); // Data type

// To get the configuration cache (Arrays or objects after parsing) from the listener, you need to call it in another coroutine
$value = $listener->getParsed($dataId, $groupId, $tenant, $type);
var_dump($type); // Data type
```

##### Manual Listening Configuration

[](#manual-listening-configuration)

> Recommend using the config listener

```
use Yurun\Nacos\Provider\Config\Model\ListenerRequest;

$md5 = '';
while (true) {
    $request = new ListenerRequest();
    $request->addListener('dataId', 'group', $md5);
    $items = $client->listen($request);
    foreach ($items as $item) {
        if ($item->getChanged()) {
            $value = $config->get($item->getDataId(), $item->getGroup(), $item->getTenant());
            var_dump('newValue:', $value);
            $md5 = md5($value);
        }
    }
}
```

### Service Discovery

[](#service-discovery)

#### Register instance

[](#register-instance)

```
$client->instance->register('192.168.1.123', 8080, 'Service1');
// Complete Parameters
$client->instance->register('192.168.1.123', 8080, 'Service1', $namespaceId = '', $weight = 1, $enabled = true, $healthy = true, $metadata = '', $clusterName = '', $groupName = '', $ephemeral = false);
```

#### Deregister instance

[](#deregister-instance)

```
$client->instance->deregister('192.168.1.123', 8080, 'Service1');
// Complete Parameters
$client->instance->deregister('192.168.1.123', 8080, 'Service1', $namespaceId = '', $clusterName = '', $groupName = '', $ephemeral = false);
```

#### Update instance

[](#update-instance)

```
$client->instance->update('192.168.1.123', 8080, 'Service1');
// Complete Parameters
$client->instance->update('192.168.1.123', 8080, 'Service1', $namespaceId = '', $weight = 1, $enabled = true, $healthy = true, $metadata = '', $clusterName = '', $groupName = '', $ephemeral = false);
```

#### Heartbeat

[](#heartbeat)

```
use Yurun\Nacos\Provider\Instance\Model\RsInfo;

$beat = new RsInfo();
$beat->setIp('192.168.1.123');
$beat->setPort(8080);
$client->instance->beat('Service1', $beat);
```

#### Get instance list

[](#get-instance-list)

```
$response = $client->instance->list('Service1');
$response = $client->instance->list('Service1', $groupName = '', $namespaceId = '', $clusters = '', $healthyOnly = false);
```

#### Get instance detail

[](#get-instance-detail)

```
$response = $client->instance->detail('192.168.1.123', 8080, 'Service1');
// Complete Parameters
$response = $client->instance->detail('192.168.1.123', 8080, 'Service1', $groupName = '', $namespaceId = '', $clusters = '', $healthyOnly = false, $ephemeral = false);
```

> Other more functional interfaces can be used by referring to the provider object's IDE tips and Nacos documentation.

Documentation
-------------

[](#documentation)

You can view the open-api documentation from the [Nacos Open API Guide](https://nacos.io/en-us/docs/open-api.html).

You can view the full documentation from the [Nacos website](https://nacos.io/en-us/docs/what-is-nacos.html).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.6% 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 ~121 days

Recently: every ~172 days

Total

7

Last Release

720d ago

Major Versions

v1.0.0 → 20220815.x-dev2022-08-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (43 commits)")[![krissss](https://avatars.githubusercontent.com/u/10680903?v=4)](https://github.com/krissss "krissss (2 commits)")

---

Tags

nacosphpswoole

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69634.4M144](/packages/algolia-algoliasearch-client-php)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.3M7](/packages/avalara-avataxclient)[keboola/storage-api-client

Keboola Storage API PHP Client

10397.4k31](/packages/keboola-storage-api-client)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.1k1](/packages/jasara-php-amzn-selling-partner-api)[flowwow/cloudpayments-php-client

cloudpayments api client

2197.1k](/packages/flowwow-cloudpayments-php-client)

PHPackages © 2026

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