PHPackages                             php-mqtt/laravel-client - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-mqtt/laravel-client

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

php-mqtt/laravel-client
=======================

A wrapper for the php-mqtt/client library for Laravel.

v1.7.0(4mo ago)228539.3k—9.6%22[1 PRs](https://github.com/php-mqtt/laravel-client/pulls)1MITPHPPHP ^8.2CI passing

Since Jan 5Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/php-mqtt/laravel-client)[ Packagist](https://packagist.org/packages/php-mqtt/laravel-client)[ Docs](https://github.com/php-mqtt/laravel-client)[ RSS](/packages/php-mqtt-laravel-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (1)

php-mqtt/laravel-client
=======================

[](#php-mqttlaravel-client)

[![Latest Stable Version](https://camo.githubusercontent.com/95381f7401fe3656c0caff0ef68cc36dd5a00b57a534ade4deb6d259db385c42/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6d7174742f6c61726176656c2d636c69656e742f76)](https://packagist.org/packages/php-mqtt/laravel-client)[![Total Downloads](https://camo.githubusercontent.com/33748ddd82cee664aac1467c75df1706a26a8385157a707f776920e637657b3e/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6d7174742f6c61726176656c2d636c69656e742f646f776e6c6f616473)](https://packagist.org/packages/php-mqtt/laravel-client)[![Tests](https://github.com/php-mqtt/laravel-client/workflows/Tests/badge.svg)](https://github.com/php-mqtt/laravel-client/actions?query=workflow%3ATests)[![Quality Gate Status](https://camo.githubusercontent.com/edc802872e14128f64bb627c69ef588b917efe0bd6c2bfb225045cdd84bebe24/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7068702d6d7174745f6c61726176656c2d636c69656e74266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)[![Maintainability Rating](https://camo.githubusercontent.com/b41358254eed1e680105d277a2def94600112d261fda315a54e4ae2e2a26dc85/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7068702d6d7174745f6c61726176656c2d636c69656e74266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)[![Reliability Rating](https://camo.githubusercontent.com/65d1897899278cb52d9917aeb4729657ee95b9505dbba7d01ae93178eefdf8d7/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7068702d6d7174745f6c61726176656c2d636c69656e74266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)[![Security Rating](https://camo.githubusercontent.com/84e1195861d10beaea96379fb02929b852ef8bc748cce5c5cc03728b59e14936/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7068702d6d7174745f6c61726176656c2d636c69656e74266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)[![Vulnerabilities](https://camo.githubusercontent.com/fd358616b5c2b72eca5e72a323874faf004479abcc920a4112d5d33d7049eedc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7068702d6d7174745f6c61726176656c2d636c69656e74266d65747269633d76756c6e65726162696c6974696573)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)[![License](https://camo.githubusercontent.com/4d4f7355cc1f937ac3fe5c39d2fb129cca7a8a8e032e84851ad4279edd01cd1a/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6d7174742f6c61726176656c2d636c69656e742f6c6963656e7365)](https://packagist.org/packages/php-mqtt/laravel-client)

`php-mqtt/laravel-client` was created by, and is maintained by [Marvin Mall](https://github.com/namoshek). It is a Laravel wrapper for the [`php-mqtt/client`](https://github.com/php-mqtt/client) package and allows you to connect to an MQTT broker where you can publish messages and subscribe to topics.

Installation
------------

[](#installation)

The package is available on [packagist.org](https://packagist.org/packages/php-mqtt/laravel-client) and can be installed using composer:

```
composer require php-mqtt/laravel-client
```

The package will register itself through Laravel auto discovery of packages. Registered will be the service provider as well as an `MQTT` facade.

After installing the package, you should publish the configuration file using

```
php artisan vendor:publish --provider="PhpMqtt\Client\MqttClientServiceProvider" --tag="config"
```

and change the configuration in `config/mqtt-client.php` according to your needs.

Configuration
-------------

[](#configuration)

The package allows you to configure multiple named connections. An initial example with inline documentation can be found in the published configuration file. Most of the configuration options are optional and come with sane defaults (especially all of the `connection_settings`).

An example configuration of two connections, where one is meant for sharing public data and one for private data, could look like the following:

```
'default_connection' => 'private',

'connections' => [
    'private' => [
        'host' => 'mqtt.example.com',
        'port' => 1883,
    ],
    'public' => [
        'host' => 'test.mosquitto.org',
        'port' => 1883,
    ],
],
```

In this example, the private connection is the default one.

*Note: it is recommended to use environment variables to configure the MQTT client. Available environment variables can be found in the configuration file.*

Usage
-----

[](#usage)

### Publish (QoS level 0)

[](#publish-qos-level-0)

Publishing a message with QoS level 0 is quite easy and can be done in a single command:

```
use PhpMqtt\Client\Facades\MQTT;

MQTT::publish('some/topic', 'Hello World!');
```

If needed, the *retain* flag (default: `false`) can be passed as third and the connection name as fourth parameter:

```
use PhpMqtt\Client\Facades\MQTT;

MQTT::publish('some/topic', 'Hello World!', true, 'public');
```

Using `MQTT::publish($topic, $message)` will implicitly call `MQTT::connection()`, but the connection will not be closed after usage. If you want to close the connection manually because your script does not need the connection anymore, you can call `MQTT:disconnect()` (optionally with the connection name as a parameter). Please also note that using `MQTT::publish($topic, $message)` will always use QoS level 0. If you need a different QoS level, you will need to use the `MqttClient` directly which is explained below.

### Publish (QoS level 1 &amp; 2)

[](#publish-qos-level-1--2)

Different to QoS level 0, we need to run an event loop in order for QoS 1 and 2 to work. This is because with a one-off command we cannot guarantee that a message reaches its target. The event loop will ensure a published message gets sent again if no acknowledgment is returned by the broker within a grace period. Only when the broker returns an acknowledgement (or all of the acknowledgements in case of QoS 2), the client will stop resending the message.

```
use PhpMqtt\Client\Facades\MQTT;

/** @var \PhpMqtt\Client\Contracts\MqttClient $mqtt */
$mqtt = MQTT::connection();
$mqtt->publish('some/topic', 'foo', 1);
$mqtt->publish('some/other/topic', 'bar', 2, true); // Retain the message
$mqtt->loop(true);
```

`$mqtt->loop()` actually starts an infinite loop. To escape it, there are multiple options. In case of simply publishing a message, all we want is to receive an acknowledgement. Therefore, we can simply pass `true` as second parameter to exit the loop as soon as all resend queues are cleared:

```
/** @var \PhpMqtt\Client\Contracts\MqttClient $mqtt */
$mqtt->loop(true, true);
```

In order to escape the loop, you can also call `$mqtt->interrupt()` which will exit the loop during the next iteration. The method can, for example, be called in a registered signal handler:

```
/** @var \PhpMqtt\Client\Contracts\MqttClient $mqtt */
pcntl_signal(SIGINT, function () use ($mqtt) {
    $mqtt->interrupt();
});
```

### Subscribe

[](#subscribe)

Very similar to publishing with QoS level 1 and 2, subscribing requires to run an event loop. Although before running the loop, topics need to be subscribed to:

```
use PhpMqtt\Client\Facades\MQTT;

/** @var \PhpMqtt\Client\Contracts\MqttClient $mqtt */
$mqtt = MQTT::connection();
$mqtt->subscribe('some/topic', function (string $topic, string $message) {
    echo sprintf('Received QoS level 1 message on topic [%s]: %s', $topic, $message);
}, 1);
$mqtt->loop(true);
```

Features
--------

[](#features)

This library allows you to use all the features provided by [`php-mqtt/client`](https://github.com/php-mqtt/client). Simply retrieve an instance of `\PhpMqtt\Client\Contracts\MqttClient` with `MQTT::connection(string $name = null)` and use it directly.

For an extensive collection of examples which explain how to use the MQTT client (directly), you can visit the [`php-mqtt/client-examples` repository](https://github.com/php-mqtt/client-examples).

License
-------

[](#license)

`php-mqtt/laravel-client` is open-source software licensed under the [MIT license](LICENSE.md).

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance76

Regular maintenance activity

Popularity55

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 53.3% 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 ~140 days

Recently: every ~191 days

Total

14

Last Release

129d ago

PHP version history (3 changes)v1.0.0-rc1PHP ^7.4|^8.0

v1.6.0PHP ^8.1

v1.7.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/38b0b9d27b847d8b05cde5b45dd0a4ae2bd6b798637e433c4c64cc865e1b8341?d=identicon)[Namoshek](/maintainers/Namoshek)

---

Top Contributors

[![Namoshek](https://avatars.githubusercontent.com/u/8877609?v=4)](https://github.com/Namoshek "Namoshek (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![stsepelin](https://avatars.githubusercontent.com/u/8102174?v=4)](https://github.com/stsepelin "stsepelin (1 commits)")[![iVampireSP](https://avatars.githubusercontent.com/u/32544186?v=4)](https://github.com/iVampireSP "iVampireSP (1 commits)")[![edo2313](https://avatars.githubusercontent.com/u/32812884?v=4)](https://github.com/edo2313 "edo2313 (1 commits)")[![bsdnomad](https://avatars.githubusercontent.com/u/5280290?v=4)](https://github.com/bsdnomad "bsdnomad (1 commits)")

---

Tags

clientlaravelpublishsubscribemqtt

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/php-mqtt-laravel-client/health.svg)

```
[![Health](https://phpackages.com/badges/php-mqtt-laravel-client/health.svg)](https://phpackages.com/packages/php-mqtt-laravel-client)
```

###  Alternatives

[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[php-mqtt/client

An MQTT client written in and for PHP.

4372.1M30](/packages/php-mqtt-client)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[bakame/laravel-domain-parser

Laravel package to integrate PHP Domain parser.

26534.8k4](/packages/bakame-laravel-domain-parser)

PHPackages © 2026

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