PHP code example of iprog / apollo-php

1. Go to this page and download the library: Download iprog/apollo-php 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/ */

    

iprog / apollo-php example snippets




$config = new ApolloPhp\Popo\Config\ApolloHttpClientConfig();
$config->setApolloServerUrl("http://172.17.18.211:3880")
    ->setApolloAppId("php-unit-test-case")
    ->setApolloCluster("DEV");
    
$apolloRedisParam = new ApolloPhp\Popo\ApolloPullParam('redis');
$apolloRedisParam->setClientIp('127.0.0.1');
$apolloRedisParam->setReleaseKey('');  

$apolloMysqlParam = new ApolloPhp\Popo\ApolloPullParam('mysql');
$apolloMysqlParam->setClientIp('127.0.0.1');
$apolloMysqlParam->setReleaseKey(''); 
  
$apolloPullParams = [$apolloRedisParam, $apolloMysqlParam];
$client = new ApolloPhp\Api\Impl\ApolloHttpClient($config);
$apolloConfigResult = $client->pullConfigs($apolloPullParams); 

// 这里会将拉取的配置保存在php对应的配置目录里面
foreach ($apolloConfigResult as $result) {
    $apolloConfig = new ApolloPhp\Config\Impl\ApolloConfig('D://config');
    $apolloConfig->parseConfig($result);
}
          



return [
    'dev' => [
        'master' => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
        'slave'  => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
    ],
    'test' => [
        'master' => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
        'slave'  => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
    ],
    'prod' => [
        'master' => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
        'slave'  => [
            'host' => '127.0.0.1',
            'port' => '6379',
            'pwd' => '#343kdjer$'
        ],
    ],
];

shell
composer