2017 © Pedro PelĂĄez
 

library consul-php-sdk

SDK to talk with consul.io API

image

caradvice/consul-php-sdk

SDK to talk with consul.io API

  • Thursday, October 6, 2016
  • by jordie
  • Repository
  • 3 Watchers
  • 0 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 42 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Consul SDK

Compatibility

This table shows this SDK compatibility regarding Guzzle version:, (*1)

SDK Version Guzzle Version
1.x >=4, <6
2.x 6

Installation

This library can be installed with composer:, (*2)

composer require sensiolabs/consul-php-sdk

Usage

The simple way to use this SDK, is to instantiate the service factory:, (*3)

$sf = new SensioLabs\Consul\ServiceFactory();

Then, a service could be retrieve from this factory:, (*4)

$kv = $sf->get('kv');

Then, a service expose few methods mapped from the consul API:, (*5)

$kv->put('test/foo/bar', 'bazinga');
$kv->get('test/foo/bar', ['raw' => true]);
$kv->delete('test/foo/bar');

All services methods follow the same convention:, (*6)

$response = $service->method($mandatoryArgument, $someOptions);
  • All API mandatory arguments are placed as first;
  • All API optional arguments are directly mapped from $someOptions;
  • All methods return raw guzzle response.

So if you want to acquire an exclusive lock:, (*7)

// Start a session
$sessionId = $session->create()->json()['ID'];

// Lock a key / value with the current session
$lockAcquired = $kv->put('tests/session/a-lock', 'a value', ['acquire' => $sessionId])->json();

if (false === $lockAcquired) {
    $session->destroy($sessionId);

    echo "The lock is already acquire by another node.\n";
    exit(1);
}

echo "Do you jobs here....";
sleep(5);
echo "End\n";

$kv->delete('tests/session/a-lock');
$session->destroy($sessionId);

Available services

  • agent
  • catalog
  • health
  • kv
  • session

Some utilities

  • Lock handler: Simple class that implement a distributed lock

The Versions

06/10 2016

dev-master

9999999-dev

SDK to talk with consul.io API

  Sources   Download

MIT

The Requires

 

by Jordie Bodlay

06/10 2016

v1.2.1

1.2.1.0

SDK to talk with consul.io API

  Sources   Download

MIT

The Requires

 

by Jordie Bodlay

06/10 2016

v1.2

1.2.0.0

SDK to talk with consul.io API

  Sources   Download

MIT

The Requires

 

by Jordie Bodlay

05/07 2016

v1.1

1.1.0.0

SDK to talk with consul.io API

  Sources   Download

MIT

The Requires

 

08/12 2014

v1.0.0

1.0.0.0

SDK to talk with consul.io API

  Sources   Download

MIT

The Requires