stefanotorresi / influxdb-php-async
InfluxDB的异步PHP客户端
0.5.0
2017-10-16 08:02 UTC
Requires
- php: ^7.1
- clue/buzz-react: ^2.1
- react/http-client: ^0.5
Requires (Dev)
- clue/block-react: ^1.2
- friendsofphp/php-cs-fixer: ^2.1
- phpunit/phpunit: ^6.0
README
一个针对InfluxDB的异步客户端,通过ReactPHP实现。
安装
使用Composer
composer require stefanotorresi/influxdb-php-async
用法
每个客户端实现都公开了三个主要方法
interface AsyncClient { public function query(string $query, array $params = []): Promise; public function write(string $payload, array $params = []): Promise; public function ping(): Promise; /* etc. */ }
默认实现使用Buzz React,我们将在本文档的其余部分中使用它。
以下是一个基本用法示例,其中我们首先创建一个数据库,然后向其中写入一行
$client = new ReactHttpClient(); $client ->query('CREATE DATABASE test') ->then(function($response) use ($client) { return $client->write('measure,tag="foo" value="bar"', ['db' => 'test']); }) ->done() ; $client->run();
请注意,您需要运行ReactPHP事件循环。如果您没有注入自己的循环,客户端将组成一个默认循环,可以通过run
方法启动。
此API假设您熟悉ReactPHP承诺。
配置
这些是默认选项
[ 'host' => 'localhost', 'port' => 8086, 'database' => '', 'username' => '', 'password' => '', 'socket_options' => [], ];
您可以在实例化时更改它们,默认值将与传入的值合并
$options = [ 'host' => 'influx-db.domain.tld', 'socket_options' => [ 'tls' => true, ], ]; $client = new ReactHttpClient($options);
有关socket_options
键的详细信息,请参阅react/socket文档。
未来开发/待办事项列表
- 使用react/datagram实现的UDP客户端。
- 一个QueryBuilder,可能和官方influxdb-php客户端中的相同。
- 一组响应解码器,将PSR-7响应的JSON体转换为更易于消费的内容。
- 探索将此包合并到官方SDK中的可能性。
许可
此软件包在MIT许可下发布。