Download the PHP package anviz/php-mqtt-client without Composer
On this page you can find all versions of the php package anviz/php-mqtt-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-mqtt-client
anviz/php-mqtt-client
php-mqtt/client
was created by, and is maintained by Jacobs.
It allows you to connect to an MQTT broker where you can publish messages and subscribe to topics.
The implementation supports all QoS levels (with limitations
Installation
This library requires PHP version 7.2 or higher.
Usage
Publish
A very basic publish example requires only three steps: connect, publish and close
If you do not want to pass a $clientId
, a random one will be generated for you. This will basically force a clean session implicitly.
Be also aware that most of the methods can throw exceptions. The above example does not add any exception handling for brevity.
Subscribe
Subscribing is a little more complex than publishing as it requires to run an event loop:
While the loop is active, you can use $mqtt->interrupt()
to send an interrupt signal to the loop. This will terminate the loop before it starts its next iteration. You can call this method using pcntl_signal(SIGINT, $handler)
for example:
Features
- MQTT Versions
- [x] v3.1
- [ ] v3.1.1
- [ ] v5.0
- Transport
- [x] TCP (unsecured)
- [x] TLS (secured, verifies the peer using a certificate authority file)
- Connect
- [x] Last Will
- [x] Last Will Topic
- [x] Last Will Message
- [x] Required QoS
- [x] Message Retention
- [x] Authentication (username & password)
- [ ] Clean Session (can be set and sent, but the client has no persistence for QoS 2 messages)
- Publish
- [x] QoS Level 0
- [x] QoS Level 1 (limitation: no persisted state across sessions)
- [x] QoS Level 2 (limitation: no persisted state across sessions)
- Subscribe
- [x] QoS Level 0
- [x] QoS Level 1
- [x] QoS Level 2 (limitation: no persisted state across sessions)
- Supported Message Length: unlimited (no limits enforced, although the MQTT protocol supports only up to 256MB which one shouldn't use even remotely anyway)
- Logging possible (
Psr\Log\LoggerInterface
can be passed to the client) - Persistence Drivers
- [x] In-Memory Driver
- [ ] Redis Driver
Limitations
- There is no guarantee that message identifiers are not used twice (while the first usage is still pending). The current implementation uses a simple counter which resets after all 65535 identifiers were used. This means that as long as the client isn't used to an extent where acknowledgements are open for a very long time, you should be fine. This also only affects QoS levels higher than 0, as QoS level 0 is a simple fire and forget mode.
- Message flows with a QoS level higher than 0 are not persisted as the default implementation uses an in-memory repository for data. To avoid issues with broken message flows, use the clean session flag to indicate that you don't care about old data.
License
anviz/php-mqtt-client
is open-sourced software licensed under the MIT license.