PHPackages                             apollo-sdk/clientd - 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. apollo-sdk/clientd

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

apollo-sdk/clientd
==================

complete implementation of Ctrip Apollo read configuration interface

1.0.0(5y ago)10354[2 issues](https://github.com/fengzhibin/apollo-sdk-clientd/issues)MITPHP

Since May 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/fengzhibin/apollo-sdk-clientd)[ Packagist](https://packagist.org/packages/apollo-sdk/clientd)[ Docs](https://github.com/fengzhibin/apollo-sdk-configd)[ RSS](/packages/apollo-sdk-clientd/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Ctrip Apollo PHP Client
=======================

[](#ctrip-apollo-php-client)

说明
--

[](#说明)

这个仓库基于apollo-sdk/config实现了常驻的阿波罗客户端，从指定阿波罗配置中心实时拉取应用的配置到本地， 通过json格式化之后缓存在本地目录

特性
--

[](#特性)

- 支持apollo配置变更的实时获取
- 支持单进程监听多个应用配置变更

安装（提供两种方式）
----------

[](#安装提供两种方式)

第一种基于git仓库运行

```
git clone git@github.com:fengzhibin/apollo-configd.git

cd apollo-configd

composer install -vvvo

php ./bin/apollo-clientd.php --help
```

第二种基于phar包运行

```
wget "https://github.com/fengzhibin/apollo-sdk-clientd/releases/download/1.0.0/apollo-clientd.phar"

php apollo-clientd.phar --help
```

启动（仅支持cli模式）
------------

[](#启动仅支持cli模式)

```
php ./bin/apollo-clientd.php --server="http://apollo-configserver.demo.com" --conf-portal="demo/test/apollo-clientd"

或者

php apollo-clientd.phar --server="http://apollo-configserver.demo.com" --conf-portal="demo/test/apollo-clientd"
```

参数说明
----

[](#参数说明)

cli启动参数

参数说明默认值--serverApollo配置中心服务的地址无--conf-portal读取额外参数配置的入口无-h显示帮助信息无--help同-h无--q开启静默模式，屏蔽运行时日志无--quiet同-q无--secret访问密钥无--cluster-name集群名default--skip-check-server是否跳过启动时检查Apollo配置中心是否合法的检查无--conf-portal-separatorconf-portal参数的分隔符/关于--conf-portal参数说明
-------------------

[](#关于--conf-portal参数说明)

\--conf-portal参数用于将一些额外的参数（例如应用id，namespace信息等）保存在阿波罗配置中心， 这样就不必在apollo-clientd启动时写死了，这也减少了apollo-clientd启动参数个数， 程序会在启动的时候到这配置入口去读取配置，这个参数格式为appid/namespace/key，以下图作为例子说明

[![Screenshot](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/extra.png)](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/extra.png)

上图的参数为--conf-portal=apollo-sdk-clientd/hello\_world/world

额外参数配置（json格式）
--------------

[](#额外参数配置json格式)

```
{
  "app_namespace_list": {//待监听配置变化的应用及应用下namespace列表配置，必填参数
    "demo1": [//应用id
      "test1",//namespace
      "haha",//namespace
    ],
    "demo2": [],//空数组代表不配置namespace列表，程序会走指定入口读取，参考下面的说明
    "demo3": []
  },
  "save_config_dir": "/data/apollo",//从阿波罗配置中心读取的配置，缓存在这个目录下，必填参数
  "app_namespace_list_portal": "application"//应用下保存namespace列表的入口，可选参数，默认为application
}
```

如果不在app\_namespace\_list里面配置应用的namespace列表（例如应用demo2和demo3）， 程序启动的时候会尝试通过以app\_namespace\_list\_portal参数为入口读取namespace列表，格式如下： [![Screenshot](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/portal.png)](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/portal.png)

程序会通过这个namespace读取当前应用下的namespace列表

完整示意图如下（只需要把当前应用下的namespace都配置在入口即可）：

[![Screenshot](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/portal_full.png)](https://raw.githubusercontent.com/fengzhibin/apollo-sdk-clientd/master/images/portal_full.png)

业务端读取配置
-------

[](#业务端读取配置)

业务上需要读取阿波罗配置时，引入apollo-sdk/clientd这个composer包即可，参考以下步骤

```
composer require apollo-sdk/clientd
```

代码上引入composer

```
require 'vendor/autoload.php';
```

例子：

```
