chat-x / mqtt
An MQTT connection dependency
1.0.2
2025-07-31 10:11 UTC
Requires
- php: >=7.4
- ext-sockets: *
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2025-09-26 09:05:21 UTC
README
A simple package that MQTT connection dependency.
Installation
You can install the package via Composer:
composer require chat-x/mqtt
Usage
use ChatX\Mqtt\MqttPHP;
Example
$mqtt = new MqttPHP('127.0.0.1', '1883', $client_id);
$mqtt->connect(true, null, null, null);
publish
$mqtt->publish('test/topic', 'Hello, MQTT!', 0);
subscribe
$callback = function($topic, $message) {
echo "Received message on topic 【{$topic}】 Message: 【{$message}】\n";
};
$topics['test/topic'] = ["qos" => 0, "function" => $callback];
$mqtt->subscribe($topics, 0);
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.