PHPackages                             jhlater/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jhlater/nacos-php

Abandoned → [jhlater/nacos-php](/?search=jhlater%2Fnacos-php)Library[Utility &amp; Helpers](/categories/utility)

jhlater/nacos-php
=================

Nacos PHP client, which also supports Swoole Coroutine

1.0.2(2y ago)019Apache-2.0PHPPHP &gt;=7.4

Since Apr 18Pushed 2y agoCompare

[ Source](https://github.com/jhlater/nacos-php)[ Packagist](https://packagist.org/packages/jhlater/nacos-php)[ RSS](/packages/jhlater-nacos-php/feed)WikiDiscussions master Synced 2d ago

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

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

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.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 ~0 days

Total

3

Last Release

806d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90f33b20c3666b01f0bb96cdca641125330f712f08287695a6f452acd4cb7385?d=identicon)[jhlater](/maintainers/jhlater)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[symfony/lock

Creates and manages locks, a mechanism to provide exclusive access to a shared resource

514139.2M692](/packages/symfony-lock)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M208](/packages/illuminate-broadcasting)[logiscape/mcp-sdk-php

Model Context Protocol SDK for PHP

368116.8k12](/packages/logiscape-mcp-sdk-php)

PHPackages © 2026

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