PHP code example of activecollab / etcd

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

    

activecollab / etcd example snippets


use use ActiveCollab\Etcd\Client as EtcdClient;

$client = new EtcdClient('http://127.0.0.1:4001');

// Get, set, update, remove key
if (!$client->exists('/key/name')) {
    $client->set('/key/name', 'value');
}
$client->set('/key/name', 'value', 10); // Set TTL
print $client->get('/key/name');

$client->update('/key/name', 'new value');

$client->remove('/key/name');

// Working with dirs
if (!$client->dirExists('/dir/path')) {
    $client->createDir('/dir/path');
}
$client->updateDir('/dir/path', 10); // Set TTL
$client->removeDir('/dir/path');

// Get dir info
$client->dirInfo('/dir/path');

// List subdirectories
$client->listDirs('/dir/path');

// Return key value map for a given dir
$client->getKeyValueMap('/dir/path')

$client = new EtcdClient('http://127.0.0.1:4001');
$client->setSandboxPath('/my/namespace');

$client->set('/key/name', 'value'); // will set /my/namespace/key/name
print $client->get('/key/name'); // will print /my/namespace/key/name

$client = new EtcdClient('http://127.0.0.1:4001');
$client->setSandboxPath('/my/namespace');

// Path relative to the current sandbox path
$client->sandboxed('./different/namespace', function(EtcdClient &$c) {
    $c->set('new_key', 123); // Sets /my/namespace/different/namespace/new_key
});

// Absolute path
$client->sandboxed('/different/namespace', function(EtcdClient &$c) {
    $c->set('new_key', 123); // Sets /different/namespace/new_key
});

print $client->getSandboxPath(); // Prints '/my/namespace'

$client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(false);

$client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(true, '/path/to/ca/file');