Mosquitood Etcd Component

1.0 2018-04-19 09:15 UTC

This package is not auto-updated.

Last update: 2019-03-15 13:19:55 UTC


README

Etcd client library for PHP

  • etcd is a distributed configuration system, part of the coreos project.
  • This repository provides a client library for etcd for PHP applications.

Installing Mosquitood\Etcd

The recommended way to install Guzzle is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of Etcd

php composer.phar require mosquitood/etcd:1.0

After installing, you need to require Composer's autoloader

require 'vendor/autoload.php';

Examples

Endpoint
require 'vendor/autoload.php';
use Mosquitood\Etcd\Endpoint;

$endpoint = new Endpoint();

//http
 $endpoint->setSchemes('http')
        ->setHost('IP')
        ->setPort('2379');
        
//https
 $endpoint->setSchemes('https')
        ->setHost('IP')
        ->setPort('2379');
        
Client
 use Mosquitood\Etcd\Client;
 
 $client = new Client($endpoint); 

 //https
 $client->setCaCert('the path of ca.pem');


 $client->set('/foo', 'fooValue');
 
 // Set the ttl
 $client->set('/foo', 'fooValue', 10);
 // get key value
 $client->get('/foo');
    
 // Update value with key
 $client->update('/foo', 'newFooValue');
    
 // Delete key
 $client->remove('/foo');

 // Create a directory
 $client->mkdir('/fooDir');
 // Remove dir
 $client->rmdir('/fooDir');
Admin
use Mosquitood\Etcd\Client;

$admin = new Admin($endpoint);

 //https
$admin->setCaCert('/root/test/ca.pem');

//version
$result = $admin->version();

print_r($result);

//health
$result = $admin->health();

print_r($result);
Member
use Mosquitood\Etcd\Member;

$member = new Member($endpoint);

 //https
$member->setCaCert('/root/test/ca.pem');

//all  members
$result = $member->all();

print_r($result);

//add member

$endPoint = new Endpoint();
$endPoint->setSchemes('http')
    ->setHost('127.0.0.2')
    ->setPort('2379');
    
$result = $member->add($endPoint);
print_r($result);

// del member

$result = $member->del($memberId);
print_r($result);

//update member

$endPoint = new Endpoint();
$endPoint->setSchemes('http')
    ->setHost('127.0.0.2')
    ->setPort('2379');
    
$result = $member->update($memberId, $endPoint);
print_r($result);

Statistics

use Mosquitood\Etcd\Statistics;

$statistics = new Statistics($endpoint);

 //https
$statistics->setCaCert('/root/test/ca.pem');

//leader statistics
$result = $statistics->leader();
print_r($result);

//self statistics
$result = $statistics->me();
print_r($result);

//store statistics
$result = $statistics->store();
print_r($result);