PHPackages                             dcarbone/simple-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. dcarbone/simple-consul-php

Abandoned → [dcarbone/php-consul-api](/?search=dcarbone%2Fphp-consul-api)Library[HTTP &amp; Networking](/categories/http)

dcarbone/simple-consul-php
==========================

PHP client for the Consul HTTP API

v2.0.2(5mo ago)792621[2 issues](https://github.com/dcarbone/php-consul-api/issues)[1 PRs](https://github.com/dcarbone/php-consul-api/pulls)Apache-2.0PHPPHP ^8.1CI passing

Since Jul 12Pushed 2mo ago7 watchersCompare

[ Source](https://github.com/dcarbone/php-consul-api)[ Packagist](https://packagist.org/packages/dcarbone/simple-consul-php)[ Docs](https://github.com/dcarbone/php-consul-api)[ GitHub Sponsors](https://github.com/dcarbone)[ Fund](https://ko-fi.com/dcarbone)[ RSS](/packages/dcarbone-simple-consul-php/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (10)Dependencies (5)Versions (55)Used By (0)

php-consul-api
==============

[](#php-consul-api)

[![Tests](https://github.com/dcarbone/php-consul-api/actions/workflows/tests.yaml/badge.svg)](https://github.com/dcarbone/php-consul-api/actions/workflows/tests.yaml)

PHP client for the [Consul HTTP API](https://www.consul.io/docs/agent/http.html)

This library is loosely based upon the [official GO client](https://github.com/hashicorp/consul/tree/main/api).

Version Compatibility
---------------------

[](#version-compatibility)

PHPConsulAPI VersionConsul Version0.3.x0.6.40.6.x0.7-0.8v1.x0.9-currentv2.x0.9-currentdev-maincurrentNewer versions of the api lib will probably work in a limited capacity with older versions of Consul, but no guarantee is made and backwards compatibility issues will not be addressed.

Composer
--------

[](#composer)

This lib is designed to be used with [Composer](https://getcomposer.org)

Require Entry:

```
{
    "require": {
        "dcarbone/php-consul-api": "^v2.0"
    }
}
```

Configuration
-------------

[](#configuration)

First, construct a [Config](./src/Config.php). This class is modeled quite closely after the [Config Struct](https://github.com/hashicorp/consul/blob/7736539db5305d267b2fd4faa6e86590ca20e556/api/api.go#L339) present in the [Consul API Subpackage](https://github.com/hashicorp/consul/tree/v1.17.2/api).

### Default Configuration

[](#default-configuration)

If you have defined some of the [Consul Environment Variables](https://www.consul.io/docs/agent/options.html)on your hosts then it would probably be easiest to simply execute the following:

```
$config = \DCarbone\PHPConsulAPI\Config::newDefaultConfig();
```

### Advanced Configuration

[](#advanced-configuration)

You may alternatively define values yourself:

```
$config = new \DCarbone\PHPConsulAPI\Config([
    'HttpClient' => $client,            // [required] Client conforming to GuzzleHttp\ClientInterface
    'Address' => 'address of server',   // [required]

    'Scheme' => 'http or https',            // [optional] defaults to "http"
    'Datacenter' => 'name of datacenter',   // [optional]
    'HttpAuth' => 'user:pass',              // [optional]
    'WaitTime' => '0s',                     // [optional] amount of time to wait on certain blockable endpoints.  go time duration string format.
    'Token' => 'auth token',                // [optional] default auth token to use
    'TokenFile' => 'file with auth token',  // [optional] file containing auth token string
    'InsecureSkipVerify' => false,          // [optional] if set to true, ignores all SSL validation
    'CAFile' => '',                         // [optional] path to ca cert file, see http://docs.guzzlephp.org/en/latest/request-options.html#verify
    'CertFile' => '',                       // [optional] path to client public key.  if set, requires KeyFile also be set
    'KeyFile' => '',                        // [optional] path to client private key.  if set, requires CertFile also be set
    'JSONEncodeOpts'=> 0,                   // [optional] php json encode opt value to use when serializing requests
]);
```

#### Configuration Note:

[](#configuration-note)

By default, this client will attempt to locate a series of environment variables to describe much of the above configuration properties. See [here](./src/Config.php) for that list, and see [here](./src/Consul.php) for a list of the env var names.

For more advanced client configuration, such as proxy configuration, you must construct your own GuzzleHttp client prior to constructing a PHPConsulAPI Config object.

As an example:

```
$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']]);
$config = new \DCarbone\PHPConsulAPI\Config([
    'HttpClient' => $proxyClient,
    'Address' => 'address of server',
]);
```

When constructing your client, if you are using the `GuzzleHttp\Client` object directly or derivative thereof, you may pass any option listed in the [Guzzle Request Options](http://docs.guzzlephp.org/en/latest/request-options.html).

Consul
------

[](#consul)

Next, construct a [Consul](./src/Consul.php) object:

```
$consul = new \DCarbone\PHPConsulAPI\Consul($config);
```

*NOTE*: If you do not create your own config object, [Consul](./src/Consul.php) will create it's own using [Config::newDefaultConfig()](./src/Config.php) and attempt to locate a suitable HTTP Client.

Once constructed, you interact with each Consul API via it's corresponding Client class:

```
$kvResp = $consul->KV->Keys();
if (null !== $kvResp->Err) {
    die($kvResp->Err);
}

var_dump($kvResp->Value);
```

...as an example.

Current Clients
---------------

[](#current-clients)

- [ACL](./src/ACL/ACLClient.php)
- [Agent](./src/Agent/AgentClient.php)
- [Catalog](./src/Catalog/CatalogClient.php)
- [Coordinate](./src/Coordinate/CoordinateClient.php)
- [Event](./src/Event/EventClient.php)
- [Health](./src/Health/HealthClient.php)
- [KV](./src/KV/KVClient.php)
- [Operator](./src/Operator/OperatorClient.php)
- [Session](./src/Session/SessionClient.php)
- [Status](./src/Status/StatusClient.php)

More will be added as time goes on!

Tests
-----

[](#tests)

The testing suite is still in it's infancy, however it is being tested directly against an actual Consul agent. They will be back-filled as time allows. Future plans are to set up a simple cluster to provide a more real-world testing scenario.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance78

Regular maintenance activity

Popularity23

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 96.5% 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.

###  Release Activity

Cadence

Every ~68 days

Recently: every ~214 days

Total

52

Last Release

171d ago

Major Versions

0.6.x-dev → v1.0.02021-02-10

v1.1.7 → v2.0.02024-02-11

PHP version history (7 changes)0.1.0PHP &gt;=5.4.0

0.3.0PHP &gt;=5.6.0

0.6.1.1PHP ^5.6 || ^7.0

v1.0.0PHP &gt;=7.4

v1.1.0PHP 7.4.\* || 8.\*

v2.0.0PHP 8.\*

v2.0.2PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/385c0c0eae1b51f1e81ee464ff6bfb3cce32589ac252ca68cc3a8aec2e3ada14?d=identicon)[dcarbone](/maintainers/dcarbone)

---

Top Contributors

[![dcarbone](https://avatars.githubusercontent.com/u/1392439?v=4)](https://github.com/dcarbone "dcarbone (416 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![slt](https://avatars.githubusercontent.com/u/2295572?v=4)](https://github.com/slt "slt (2 commits)")[![kai890707](https://avatars.githubusercontent.com/u/62149120?v=4)](https://github.com/kai890707 "kai890707 (1 commits)")[![Perovmpr](https://avatars.githubusercontent.com/u/23420698?v=4)](https://github.com/Perovmpr "Perovmpr (1 commits)")[![sactor](https://avatars.githubusercontent.com/u/598282?v=4)](https://github.com/sactor "sactor (1 commits)")[![urosgruber](https://avatars.githubusercontent.com/u/590455?v=4)](https://github.com/urosgruber "urosgruber (1 commits)")[![cjones-vultr](https://avatars.githubusercontent.com/u/184550036?v=4)](https://github.com/cjones-vultr "cjones-vultr (1 commits)")[![wiggels](https://avatars.githubusercontent.com/u/16748278?v=4)](https://github.com/wiggels "wiggels (1 commits)")[![dmitriyGarden](https://avatars.githubusercontent.com/u/13615330?v=4)](https://github.com/dmitriyGarden "dmitriyGarden (1 commits)")[![fsotsk](https://avatars.githubusercontent.com/u/7643673?v=4)](https://github.com/fsotsk "fsotsk (1 commits)")

---

Tags

consulconsul-apiphpphp-clientconsulconsul-apiphp-consul-api

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[spatie/crawler

Crawl all internal links found on a website

2.8k17.7M58](/packages/spatie-crawler)[dcarbone/php-consul-api

PHP client for the Consul HTTP API

79401.6k8](/packages/dcarbone-php-consul-api)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[guzzlehttp/guzzle-services

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.

25510.9M189](/packages/guzzlehttp-guzzle-services)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34199.5k2](/packages/onesignal-onesignal-php-api)

PHPackages © 2026

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