2017 © Pedro Peláez
 

library apollo-client

apollo client for php

image

multilinguals/apollo-client

apollo client for php

  • Friday, July 6, 2018
  • by xiaodx12
  • Repository
  • 1 Watchers
  • 4 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

携程Apollo的PHP客户端

install

php version >= 7.0, (*1)

$ composer require multilinguals/apollo-client

php version >= 5.4 , <7.0, (*2)

$ composer require multilinguals/apollo-client --ignore-platform-reqs

Features

  • 支持apollo配置变更的实时获取
  • 支持拉取配置后自定义的回调处理

Usage

客户端以cli的方式后台启动执行,支持apollo配置的适时获取,并将配置保存在指定的目录供应用程序读取解析, (*3)

客户端示例代码

#!/usr/bin/env php
<?php
require 'vender/autoload.php'; // autoload
use Org\Multilinguals\Apollo\Client\ApolloClient;

//specify address of apollo server
$server = getenv('CONFIG_SERVER'); // get server address from env

//specify your appid at apollo config server
$appid = getenv('APPID'); // get appid from env

//specify namespaces of appid at apollo config server
$namespaces = getenv('NAMESPACE'); // get namespaces from env
$namespaces = explode(',', $namespaces);

$apollo = new ApolloClient($server, $appid, $namespaces);

if ($clientIp = getenv('CLIENTIP')) {
    $apollo->setClientIp($clientIp);
}

ini_set('memory_limit','128M');
$pid = getmypid();
echo "start [$pid]\n";
$restart = true; //auto start if failed
do {
    $error = $apollo->start();
    if ($error) echo('error:'.$error."\n");
}while($error && $restart);

配置管理

拉取的配置默认保存在脚本所在目录,每个namespace的配置以apolloConfig.{$namespaceName}.php的方式命名保存, (*4)

Docker环境客户端自启动

在docker的启动脚本中加入启动代码,一般的php容器启动脚本是docker-php-entrypoint, (*5)

if [ -f "/path/to/start.php" ]; then
    apollo_ps=$(ps -aux | grep -c "php /path/to/start.php")
    if [ $apollo_ps -eq 1 ]; then
        php /path/to/start.php &
    fi
fi

The Versions

06/07 2018

dev-master

9999999-dev https://github.com/multilinguals/apollo-php-client

apollo client for php

  Sources   Download

MIT

The Requires

  • php ~7.0

 

client apollo

06/07 2018

dev-dev

dev-dev https://github.com/multilinguals/apollo-php-client

apollo client for php

  Sources   Download

MIT

The Requires

  • php ~7.0

 

client apollo

06/07 2018

v0.1.0

0.1.0.0 https://github.com/multilinguals/apollo-php-client

apollo client for php

  Sources   Download

MIT

The Requires

  • php ~7.0

 

client apollo