adachsoft / mqtt-adapter
A PHP adapter that connects the AdachSoft MQTT contract to php-mqtt/client.
v0.1.0
2026-11-08 08:35 UTC
Requires
- php: >=8.2
- adachsoft/mqtt-contract: ^0.1
- php-mqtt/client: ^1.0|^2.0
- psr/log: ^2.0|^3.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.2
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-09 06:14:07 UTC
README
A PHP adapter that connects the transport-independent AdachSoft MQTT contract to php-mqtt/client.
Features
- Provides the
MqttClientInterfaceimplementation through a public factory. - Supports raw and JSON message subscriptions, publishing, quality-of-service levels, and retained messages.
- Accepts optional broker credentials and a PSR-3 logger.
- Converts transport-client failures into the contract's
MqttException. - Supports graceful event-loop interruption through system signals when
pcntlis available.
Requirements
- PHP 8.2 or later.
- An MQTT broker reachable by the application.
Installation
composer require adachsoft/mqtt-adapter
Quick start
<?php
declare(strict_types=1);
use AdachSoft\Mqtt\Adapter\Factory\PhpMqttClientAdapterFactory;
require __DIR__ . '/vendor/autoload.php';
$client = (new PhpMqttClientAdapterFactory())->create(
host: 'localhost',
port: 1883,
clientId: 'temperature-monitor',
);
$client->connect();
$client->initCntlSignal();
$client->subscribe('sensors/temperature', static function (string $topic, string $payload): void {
printf("%s: %s\n", $topic, $payload);
}, qualityOfService: 1);
// The event loop runs until it is interrupted, for example by SIGINT.
$client->loop();
$client->close();
The factory also accepts optional username, password, and PSR-3 logger arguments. Use publish() to send a raw payload, or publishMessage() to publish a MessageVo from the contract package.
Examples
License
This package is distributed under the MIT license.