PHPackages                             br/consul-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. br/consul-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

br/consul-php
=============

PHP library to interact with the consul.io service

243007[1 issues](https://github.com/baldurrensch/consul-php/issues)PHP

Since Oct 10Pushed 11y ago2 watchersCompare

[ Source](https://github.com/baldurrensch/consul-php)[ Packagist](https://packagist.org/packages/br/consul-php)[ RSS](/packages/br-consul-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Consul.io PHP library
=====================

[](#consulio-php-library)

[![Build Status](https://camo.githubusercontent.com/dca7525c54f69acd61c56f0d8cf565d9c58bb9368541c58c9a5c1c50b0a3aae0/68747470733a2f2f7472617669732d63692e6f72672f62616c64757272656e7363682f636f6e73756c2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/baldurrensch/consul-php)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/335d5247b991bdbbeebac01ffa4bd052d95aa1e20f6232311ced7ff4924988bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62616c64757272656e7363682f636f6e73756c2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f733d34376363666433303439303930393966346135653132343164633364333064623866386430313334)](https://scrutinizer-ci.com/g/baldurrensch/consul-php/)[![Code Coverage](https://camo.githubusercontent.com/363a4cd514ad192a33ab339be1174dfb33f8b9154969b847fbff0531eb662da3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62616c64757272656e7363682f636f6e73756c2d7068702f6261646765732f636f7665726167652e706e673f733d32616161373763326666626437643533333261343364303466383132313666376233326431636235)](https://scrutinizer-ci.com/g/baldurrensch/consul-php/)[![SensioLabsInsight](https://camo.githubusercontent.com/18e8e6d35bc3d2015aa09dc9d4e47198ceefde4170a6ad3b7863e22cb48fc8df/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33656664386131642d343431312d343862362d393865372d6337663638356131396236612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3efd8a1d-4411-48b6-98e7-c7f685a19b6a)

This is a PHP library for the [consul.io](http://www.consul.io/) application. Note that this is in development right now. Feel free to open PRs.

Installation
------------

[](#installation)

1. Require the package via composer

```
$ composer require "br/consul-php"
```

2. Instantiate the library:

Depending on which part of the library you want to use, instantiate the correct Client:

```
$client = new \BR\Consul\Agent('http://localhost:8500'); // to issue commands to the local agent
$client = new \BR\Consul\KeyValueStore('http://localhost:8500'); // to access the Key Value Store
```

Usage
-----

[](#usage)

### 1. Key/Value Store

[](#1-keyvalue-store)

Use the `getValue()`, `setValue()` and `deleteValue()` functions of the client. Example:

```
$client->setValue('myKey', 'myValue');
$client->setValue('myKey', 'myValue', 'datacenter-east'); // Set the value in the datacenter-east datacenter

$client->getValue('myKey');
$client->getValue('myKey', 'datacenter-east'); // Get the value from the datacenter-east datacenter

$client->deleteValue('myKey');
$client->deleteValue('myKey', 'datacenter-east'); // Delete the value from the datacenter-east datacenter
```

### 2. Agent

[](#2-agent)

#### 2.1 Registering a service with the agent

[](#21-registering-a-service-with-the-agent)

In order to register a service, you have to create a `BR\Consul\Model\Service` object, and pass it to the `Client::registerService()` function. Example:

```
$service = new \BR\Consul\Model\Service();
$service->setName('postgres');
$service->setId('postgres-1');
$service->setTags(['master']);
$service->setPort(5432);

$success = $client->registerService($service);
```

#### 2.2 Retrieving a list of all services registered with the agent

[](#22-retrieving-a-list-of-all-services-registered-with-the-agent)

You can retrieve a list of services that are registered with the agent. Example:

```
$services = $service->getServices();
var_dump(count($services));

/** $srv \BR\Consul\Model\Service */
foreach ($services as $srv) {
    echo $srv->getName()
}
```

#### 2.3 Removing a service from the agent

[](#23-removing-a-service-from-the-agent)

```
$client->deregisterService('postgres-1');
// alternatively
$client->removeService($service);
```

### 3. Catalog

[](#3-catalog)

#### 3.1. Get a list of datacenters

[](#31-get-a-list-of-datacenters)

```
$datacenters = $client->getDatacenters();
var_dump(count($datacenters));

/** $datacenter \BR\Consul\Model\Datacenter */
foreach ($datacenters as $datacenter) {
    echo $datacenter->getName();
}
```

Tests
-----

[](#tests)

Run the unit and functional tests by running `phpunit` in the root of the repository.

To run consul, use:

```
$ ./consul agent -data-dir . --bootstrap -server
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/70618696?v=4)[Brendan Schlosser](/maintainers/brensch)[@brensch](https://github.com/brensch)

---

Top Contributors

[![baldurrensch](https://avatars.githubusercontent.com/u/871417?v=4)](https://github.com/baldurrensch "baldurrensch (28 commits)")

### Embed Badge

![Health badge](/badges/br-consul-php/health.svg)

```
[![Health](https://phpackages.com/badges/br-consul-php/health.svg)](https://phpackages.com/packages/br-consul-php)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
