datingvip / etcd-php
PHP的Etcd客户端库
dev-master
2024-01-11 12:00 UTC
Requires
- php: >=8
- ext-curl: *
- symfony/console: ~5 || ~6 || ~7
Requires (Dev)
- phpunit/phpunit: ~8
This package is auto-updated.
Last update: 2024-09-11 13:22:14 UTC
README
etcd是一个分布式配置系统,是coreos项目的核心部分。
该存储库为PHP应用程序提供了etcd客户端库。受linkorb/etcd-php的启发。为了我们的目的,我们需要一个更灵活的etcd客户端版本。它可以与预定义的HTTP客户端(无论是什么)一起使用,并且也支持PHP 7.1。
etcd-php使用curl库作为默认客户端并创建自己的http客户端实例。
安装etcd
要安装etcd,请按照项目发布页面上的etcd团队发布的说明进行操作
https://github.com/DatingVIP/etcd/releases/
安装datingvip/etcd
最简单的方法是使用composer进行安装
{ "require" : { "DatingVIP/etcd": "^1.0" } }
使用客户端
use use DatingVIP\Component\Etcd\Client; $client = new Client('http://127.0.0.1:4001'); // If you have own http client object & if it has proper adapter // proper means - need to implement DatingVIP\Component\Etcd\Client\HttpInterface) $httpAdapter = new MyAdapter($myHttpClient); $client->setHttpClient($httpAdapter); // Get, set, update, remove key if (!$client->keyExists('/key/name')) { $client->keySet('/key/name', 'value'); } $client->set('/key/name', 'value', 10); // Set TTL print $client->keyGet('/key/name'); $client->keyUpdate('/key/name', 'new value'); $client->keyRemove('/key/name'); // Working with dirs if (!$client->dirExists('/dir/path')) { $client->dirCreate('/dir/path'); } $client->dirUpdate('/dir/path', 10); // Set TTL $client->dirRemove('/dir/path'); // Get dir info $client->dirInfo('/dir/path'); // List subdirectories $client->dirList('/dir/path');
SSL
客户端可以配置为不验证SSL对等方
$client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(false);
以及使用自定义CA文件
$client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(true, '/path/to/ca/file');