PHPackages                             stefanak-michal/thingsdb-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. stefanak-michal/thingsdb-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

stefanak-michal/thingsdb-php
============================

PHP connector for ThingsDB

v1.1.0(6mo ago)38711Apache-2.0PHPPHP ^8.2

Since Mar 29Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/stefanak-michal/thingsdb-php)[ Packagist](https://packagist.org/packages/stefanak-michal/thingsdb-php)[ Docs](https://github.com/stefanak-michal/thingsdb-php)[ Fund](https://ko-fi.com/michalstefanak)[ RSS](/packages/stefanak-michal-thingsdb-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

ThingsDB PHP client
===================

[](#thingsdb-php-client)

PHP library for communication with [ThingsDB](https://www.thingsdb.io/) over TCP socket.

[![ko-fi](https://camo.githubusercontent.com/201ef269611db7eb6b5d08e9f756ab8980df3014b64492770bdf13a6ed924641/68747470733a2f2f6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/Z8Z5ABMLW)

✅ Requirements
--------------

[](#white_check_mark-requirements)

- ThingsDB [v1](https://docs.thingsdb.io/v1/)
- PHP ^8.2
- [rybakit/msgpack](https://github.com/rybakit/msgpack.php)
- [mbstring](https://www.php.net/manual/en/book.mbstring.php)
- [openssl](https://www.php.net/manual/en/book.openssl.php) - Required only for connection with enabled SSL

💾 Installation - Composer
-------------------------

[](#floppy_disk-installation---composer)

Run the following command in your project to install the latest applicable version of the package:

`composer require stefanak-michal/thingsdb-php`

[Packagist](https://packagist.org/packages/stefanak-michal/thingsdb-php)

🖥️ Usage
--------

[](#desktop_computer-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

[](#available-methods)

MethodDescription\_\_constructThingsDB constructor - immediately connect to provided uri.pingPing, useful as keep-aliveauthAuthorization with username and passwordauthTokenAuthorization with tokenqueryQuery ThingsDBrunRun a procedurejoinJoin one or more room(s)leaveLeave one or more room(s)emitEmit an event to a roomemitPeersEmit an event to a room peerslisteningListen for incoming packages### Listening

[](#listening)

Listening is specific state in which you wait for emitted packages from ThingsDB. You can read more about it in [docs](https://docs.thingsdb.io/v1/listening/). 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

[](#example)

```
use ThingsDB\ThingsDB;

$thingsDB = new ThingsDB();
$result = $thingsDB->auth(); // returns true on success
$message = $thingsDB->query('@:stuff', '"Hello World!";'); // returns "Hello World!"
```

🔒 SSL
-----

[](#lock-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](https://www.php.net/manual/en/function.stream-context-create.php) 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
----------

[](#stopwatch-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
-----

[](#error)

### \\ThingsDB\\error\\ConnectException

[](#thingsdberrorconnectexception)

This exception class is used for any exception related to connection on client side.

### \\ThingsDB\\error\\PackageException

[](#thingsdberrorpackageexception)

This exception class is used when error occurs in ThingsDB. [list of error types](https://docs.thingsdb.io/v1/errors/)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance77

Regular maintenance activity

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~296 days

Total

3

Last Release

187d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04e29b3719023eae810d2f457310ac2f7deb64314e53795ca135dafd505ce4b2?d=identicon)[oLDo](/maintainers/oLDo)

---

Top Contributors

[![stefanak-michal](https://avatars.githubusercontent.com/u/5502917?v=4)](https://github.com/stefanak-michal "stefanak-michal (18 commits)")[![joente](https://avatars.githubusercontent.com/u/6572730?v=4)](https://github.com/joente "joente (3 commits)")

---

Tags

driverphpthingsdbphpSocketthingsdb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stefanak-michal-thingsdb-php/health.svg)

```
[![Health](https://phpackages.com/badges/stefanak-michal-thingsdb-php/health.svg)](https://phpackages.com/packages/stefanak-michal-thingsdb-php)
```

###  Alternatives

[iris/nsq_to_swoole

a strong php client for NSQ using swoole extension

354.8k](/packages/iris-nsq-to-swoole)[warriorxk/phpwebsockets

A websocket library with support for IPC using socket pairs

1225.3k](/packages/warriorxk-phpwebsockets)[sockeon/sockeon

Framework-agnostic PHP WebSocket and HTTP server library with attribute-based routing and support for namespaces and rooms.

291.3k2](/packages/sockeon-sockeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
