PHP code example of arunfung / php-apollo

1. Go to this page and download the library: Download arunfung/php-apollo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arunfung / php-apollo example snippets




use ArunFung\PhpApollo\ApolloClient;

// apollo 服务地址
$server = '';
// apollo 后台配置的 APP ID
$app_id = 0;
// apollo 后台配置的命名空间
$namespaces = [
    "application",
    "datasource",
];

// 实例化 Apollo Client
$testApolloClient = new ApolloClient($server,$app_id,$namespaces);
// 模板文件夹
$testApolloClient->setEnvExamplePath(__DIR__);
// 模板文件名
$testApolloClient->setEnvExample('.env.example');
// env 配置文件夹
$testApolloClient->setEnvPath(__DIR__);
// env 文件名
$testApolloClient->setEnv('.env');

// 拉取 Apollo 的配置写入本地配置文件(适合定时或者单次触发拉取配置)
$testApolloClient->pullConfigs();

// 开启应用感知配置更新并写入本地配置文件
$testApolloClient->start();

// 配置默认缓存目录 /var/www/php-apollo-cache
// 也可以自定义缓存目录
$cache_path = '/data/apollo';
$testApolloClient->setCachePath($cache_path);
 bash
composer