loranger/questdb-client
Composer 安装命令:
composer require loranger/questdb-client
包简介
Simple PHP QuestDB client using Influx Line Protocol
README 文档
README
Simple PHP QuestDB PHP client using Influx Line Protocol.
Formats ILP query string regarding QuestDB datatypes provided
Requirements
PHP 7+ server with sockets extension enabled.
Install
Clone this repository or use composer
composer require loranger/questdb-client
Usage
\QuestDB\Client wrapper is provided as a singleton class.
Server config
Call the setServer method to define your QuestDB host.
\QuestDB\Client::setServer('questdb_server', 9009);
Sending datas
You can send datas to your QuestDB server using the ping method, by providing an ILP query string or an associative array
ILP syntax
Use the ILP syntax to send your datas
\QuestDB\Client::ping('trades,symbol=BTC-USD,side=sell');
ILP Query Builder
You can use the ILP Query Builder to generate query string from array values
new \QuestDB\ILPQueryBuilder(string $table, array $values, int $timestamp = null);
$ilp_query = new \QuestDB\ILPQueryBuilder('trades', [ 'symbol' => 'BTC-USD', 'side' => 'sell' ]); echo $ilp_query; // trades,symbol=BTC-USD,side=sell \QuestDB\Client::ping($ilp_query);
The ping method is compliant with the ILPQueryBuilder constructor signature, so you can directly pass the argument to the ping method
\QuestDB\Client::ping('trades', [ 'symbol' => 'BTC-USD', 'side' => 'sell' ], time());
The given values are automatically considered as symbol datatypes, but you can specify any QuestDB type if you need more precision:
\QuestDB\Client::ping('trips', [ 'cab_type:symbol' => 'yellow', 'passenger_count:int' => 3, 'trip_distance:double' => 6.3, 'payment_type' => 'cash', ]);
which will build the same IPL query as
echo (new \QuestDB\ILPQueryBuilder('trips', [ 'cab_type:symbol' => 'yellow', 'passenger_count:int' => 3, 'trip_distance:double' => 6.3, 'payment_type' => 'cash', ])); // trips,cab_type=yellow,payment_type=cash passenger_count=3i,trip_distance=6.300000
Docker
A docker compose file is provided in order to run a local short demo along with a questdb server.
The container is composed by:
- a php 7 image (locally build with its sockets extensions)
- a composer image inherited from php image
- a pest image inherited from php image
- a dockerized questdb server
The PHP image runs the builtin server and expose the port 80 (but can also be used with traefik).
The composer image should exit as soon as the container starts. It only provides a convenient shortcut to run composer command within the container: docker-compose run --rm composer show --platform
The pest image is a shortcut to the composer locally installed pest binary. It provides a shortcut to run tests: docker-compose run --rm pest --version
The questdb image runs the latest official docker image and exposes ports 9000 and 9009 (but can also be used with traefik).
cp .env.example .env cp docker-compose.example docker-compose.yml docker compose up
loranger/questdb-client 适用场景与选型建议
loranger/questdb-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 loranger/questdb-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 loranger/questdb-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-09