PHPackages                             angry-big-cat/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. [HTTP &amp; Networking](/categories/http)
4. /
5. angry-big-cat/laravel-client

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

angry-big-cat/laravel-client
============================

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

v1.6.0(2y ago)05MITPHPPHP ^7.4|^8.0

Since Jan 5Pushed 2y agoCompare

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

READMEChangelogDependencies (4)Versions (14)Used By (0)

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.

If you are using Lumen, you need to manually add the following code to `bootstrap/app.php`:

```
$app->register(\PhpMqtt\Client\MqttClientServiceProvider::class);
```

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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 66.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 ~108 days

Recently: every ~92 days

Total

12

Last Release

763d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9284beea407527f94392fccd925a890b7de9f7140cad10b6077eeaa52da6d217?d=identicon)[AngryBigCat](/maintainers/AngryBigCat)

---

Top Contributors

[![Namoshek](https://avatars.githubusercontent.com/u/8877609?v=4)](https://github.com/Namoshek "Namoshek (20 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![shenguu](https://avatars.githubusercontent.com/u/53547570?v=4)](https://github.com/shenguu "shenguu (2 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/angry-big-cat-laravel-client/health.svg)

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

###  Alternatives

[php-mqtt/laravel-client

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

228539.3k1](/packages/php-mqtt-laravel-client)[php-mqtt/client

An MQTT client written in and for PHP.

4372.1M30](/packages/php-mqtt-client)[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

400509.0k3](/packages/pusher-pusher-http-laravel)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59300.2k11](/packages/vinelab-http)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

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