PHP code example of leeqvip / php-apollo

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

    

leeqvip / php-apollo example snippets




eeqvip\Apollo\Apollo;

// Initialize Apollo client
$apollo = Apollo::getInstance([
    'app_id' => 'YOUR_APP_ID',
    'server_url' => 'http://localhost:8080', // Apollo server address
    'cluster' => 'default', // Cluster name
    'namespaces' => ['application'], // Namespace list
    'cache_dir' => __DIR__ . '/cache', // Cache directory
    'secret' => 'YOUR_SECRET',
]);

$apollo->load();

// Get configuration
$value = $apollo->get('key', 'default');
echo "Configuration value: $value\n";

// Get all configurations
$configs = $apollo->getAll();
print_r($configs);



eeqvip\Apollo\Apollo;

// Initialize Apollo client
$apollo = Apollo::getInstance([
    'app_id' => 'YOUR_APP_ID',
    'server_url' => 'http://localhost:8080',
]);

// Register configuration change callback
$apollo->onUpdate(function ($configs, $namespace) {
    echo "Configuration changed - Namespace: $namespace\n";
    print_r($configs);
});

// Start listening (blocking)
$apollo->listen();



eeqvip\Apollo\Apollo;

// Initialize Apollo client with multiple namespaces
$apollo = Apollo::getInstance([
    'app_id' => 'YOUR_APP_ID',
    'server_url' => 'http://localhost:8080',
    'namespaces' => ['application', 'TEST1.application.yml', 'config.json'],
]);

// Get configurations from different namespaces
$appConfig = $apollo->get('key', 'default', 'application');
$testConfig = $apollo->get('key', 'default', 'TEST1.application.yml');
$jsonConfig = $apollo->get('key', 'default', 'config.json');
bash
composer