PHPackages                             yuanlj-tea/apollo-client - 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. yuanlj-tea/apollo-client

ActiveLibrary[API Development](/categories/api)

yuanlj-tea/apollo-client
========================

php apollo client

1.0.2(5y ago)23MITPHPPHP &gt;=7.1

Since Aug 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/yuanlj-tea/apollo-client)[ Packagist](https://packagist.org/packages/yuanlj-tea/apollo-client)[ RSS](/packages/yuanlj-tea-apollo-client/feed)WikiDiscussions master Synced today

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

#### apollo-client

[](#apollo-client)

---

[协程apollo](https://github.com/ctripcorp/apollo) php client for laravel

#### 1、安装

[](#1安装)

```
composer require yuanlj-tea/apollo-client
```

#### 2、使用

[](#2使用)

```
require_once __DIR__ . '/../vendor/autoload.php';
use ApolloClient\ApolloClient;

$base_url = 'http://xxx';
$appid = 'xxx';
$namespace = ['xxx'];

$cluster = 'default';
$envDir = __DIR__ . '/../env';
$saveDir = __DIR__ . '/../src';

$client = new ApolloClient($base_url, $appid, $namespace);
//方式1：依赖模板文件
$client->setCluster($cluster)    		//设置集群名
  ->setEnvFileName('env-2')         //设置env文件名
  // ->setTplFileName('tpl.php')  	//设置env模板文件名
  ->setEnvTemplateDir($envDir)      //设置env模板文件所在路径
  ->setEnvSavedDir($saveDir);       //设置env文件的存储路径
$client->startLongPull(1);

//方式2：不依赖模板文件，把apollo的配置文件放入env
$envFullPath = __DIR__ . '/../src/.env-3';
$client->setCluster($cluster)       //设置集群名
	->setEnvPath($envFullPath);       //设置env文件存储的完整路径
$client->startLongPull(2);

//方式3：自行传入闭包自定义env生成方式
$callBack = function($data){
  // do sth
};
$client->startLongPull(3,$callBack);
```

#### 3、方法说明

[](#3方法说明)

```
setEnvFileName($envFileName)//设置要生成的env模板文件名

setEnvSavedDir($envSavedDir)//设置env要保存到的文件夹

setEnvPath($fullPath)//设置env文件要保存的全路径

setTplFileName($tplFileName)//设置env模板文件名

setEnvTemplateDir($envTemplateDir)//设置env模板文件

setEnvTplPath($fullPath)//设置要依赖的env模板文件的全路径

setCluster($cluster)//设置集群名

setClientIp()//设置client ip

startLongPull($type = 1, \Closure $callback_param = null)//开始从apollo拉取配置
```

---

#### 4、在laravel中使用

[](#4在laravel中使用)

##### 4.1、创建配置文件

[](#41创建配置文件)

```
php artisan vendor:publish --tag=apollo --force(强制替换已有的配置文件)

会在config_path()下生成apollo.php
```

##### 4.2、在 `config/app.php`注册 ServiceProvider 和 Facade

[](#42在-configappphp注册-serviceprovider-和-facade)

```
'providers' => [
    // ...
    ApolloClient\ApolloClientServiceProvider::class,
],
'aliases' => [
    // ...
    'Apollo' => ApolloClient\ApolloFacade::class,
],
```

##### 4.3、三种方式获取服务实例

[](#43三种方式获取服务实例)

方法参数注入

```
public function handle(ApolloClient $apollo)
{
		$apollo->doSth();
}
```

通过服务名获取

```
public function handle()
{
    app('apollo_client')->setEnvFileName('env.prod')
        ->setEnvSavedDir($saveDir)
        ->startLongPull(2);
}
```

通过门面类获取

```
use Apollo;

public function handle()
{
    $envTplDir = app_path().'/env';
    $saveDir = realpath(app_path() . '/../');

  	Apollo::setEnvFileName('env.prod')
    		->setEnvSavedDir($saveDir)
    		->startLongPull(2);
}
```

License
-------

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

2099d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10fba85f48f36c98b9759fdb71a2b6495d5d2a6593e12668a7121dc0f0a0c525?d=identicon)[yuanlj-tea](/maintainers/yuanlj-tea)

---

Top Contributors

[![yuanlj-tea](https://avatars.githubusercontent.com/u/20747808?v=4)](https://github.com/yuanlj-tea "yuanlj-tea (7 commits)")

### Embed Badge

![Health badge](/badges/yuanlj-tea-apollo-client/health.svg)

```
[![Health](https://phpackages.com/badges/yuanlj-tea-apollo-client/health.svg)](https://phpackages.com/packages/yuanlj-tea-apollo-client)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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