Skip to content
PHP Consul SDK
Branch: master
Clone or download
lyrixx minor #40 Exclude the bin folder from archive (Jens Olsson)
This PR was merged into the 2.0-dev branch.


Exclude the bin folder from archive

This makes sure that the Cosul binaries used for testing are not
distributed in the Composer package.


caf8075 Exclude the bin folder from archive
Latest commit 508b19c Apr 11, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Consul allow user to pass consistency mode when reading kv store data. Feb 12, 2019
bin Add consul for test environment, phpunit, and fix Aug 24, 2018
consul-configuration Be kind with case insensitive file systems Nov 17, 2014

Consul SDK


This table shows this SDK compatibility regarding Guzzle version:

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


This library can be installed with composer:

composer require sensiolabs/consul-php-sdk


The simple way to use this SDK, is to instantiate the service factory:

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

Then, a service could be retrieve from this factory:

$kv = $sf->get(\SensioLabs\Consul\Services\KVInterface::class);

Then, a service expose few methods mapped from the consul API:

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

All services methods follow the same convention:

$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:

// 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) {

    echo "The lock is already acquire by another node.\n";

echo "Do you jobs here....";
echo "End\n";


Available services

  • agent
  • catalog
  • health
  • kv
  • session

Some utilities

  • Lock handler: Simple class that implement a distributed lock
You can’t perform that action at this time.