stefanak-michal/thingsdb-php
Composer 安装命令:
composer require stefanak-michal/thingsdb-php
包简介
PHP connector for ThingsDB
README 文档
README
PHP library for communication with ThingsDB over TCP socket.
✅ Requirements
- ThingsDB v1
- PHP ^8.2
- rybakit/msgpack
- mbstring
- openssl - Required only for connection with enabled SSL
💾 Installation - Composer
Run the following command in your project to install the latest applicable version of the package:
composer require stefanak-michal/thingsdb-php
🖥️ Usage
Class \ThingsDB\ThingsDB provide all functionality related to socket connection with ThingsDB. It contains set of method which are based on documentation.
Every method has comment (annotation) with required information and link to documentation.
Available methods
| Method | Description |
|---|---|
| __construct | ThingsDB constructor - immediately connect to provided uri. |
| ping | Ping, useful as keep-alive |
| auth | Authorization with username and password |
| authToken | Authorization with token |
| query | Query ThingsDB |
| run | Run a procedure |
| join | Join one or more room(s) |
| leave | Leave one or more room(s) |
| emit | Emit an event to a room |
| emitPeers | Emit an event to a room peers |
| listening | Listen for incoming packages |
Listening
Listening is specific state in which you wait for emitted packages from ThingsDB. You can read more about it in docs. PHP has max_execution_time and it is not allowed to set higher value than this. With max_execution_time=0 you can of course wait indefinitely.
join, emit, leave also emit package towards the one who did it. Therefore, don't be surprised when first package received with calling listening will be ON_JOIN|ON_LEAVE|ON_EMIT event type.
Example
use ThingsDB\ThingsDB; $thingsDB = new ThingsDB(); $result = $thingsDB->auth(); // returns true on success $message = $thingsDB->query('@:stuff', '"Hello World!";'); // returns "Hello World!"
🔒 SSL
To make connection with enabled SSL you can use third parameter of constructor which is context. This context is provided to stream_context_create when creating connection. verify_peer is the bare minimum to enable SSL communication.
use ThingsDB\ThingsDB; $thingsDB = new ThingsDB('localhost:9200', 15, [ 'socket' => ['tcp_nodelay' => true], 'ssl' => ['verify_peer' => true] ]);
⏱️ Timeout
Class constructor contains $timeout argument. This timeout is for established socket connection. To set up
timeout for establishing socket connection itself you have to set ini directive default_socket_timeout.
Setting up ini directive isn't part of connection class because function ini_set can be disabled on production
environments for security reasons.
Error
\ThingsDB\error\ConnectException
This exception class is used for any exception related to connection on client side.
\ThingsDB\error\PackageException
This exception class is used when error occurs in ThingsDB. list of error types
stefanak-michal/thingsdb-php 适用场景与选型建议
stefanak-michal/thingsdb-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「Socket」 「thingsdb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stefanak-michal/thingsdb-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stefanak-michal/thingsdb-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stefanak-michal/thingsdb-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
NO LIBRARIES socket per page bridge for your Laravel application.
Free PHP WebSocket
A light weight PHP http client implements PSR7, use socket/curl for sending requests.
Alfabank REST API integration
Está é uma biblioteca genérica voltada a efetuar testes/verificação de conectividade
PHP client for connection to Graphene node (crea)
统计信息
- 总下载量: 1.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-03-28