PHP code example of poplary / consul-sdk
1. Go to this page and download the library: Download poplary/consul-sdk library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
poplary / consul-sdk example snippets
// 获取 Consul 中已经注册的服务列表
$consulService = new ServiceFactory(['base_uri' => 'http://xxx.xxx.xxx.xxx:8500']);
// 获取不同 API 的服务
$catalog = $consulService->get(CatalogInterface::class);
// 调用 Consul 的 API 接口,返回的 $response 变量为一个 Poplary\Consul\ConsulResponse 对象,可以使用类的方法进行解析
$response = $catalog->service('service_name');
AgentInterface.php
CatalogInterface.php
HealthInterface.php
KVInterface.php
SessionInterface.php