Download the PHP package php-mqtt/laravel-client without Composer

On this page you can find all versions of the php package php-mqtt/laravel-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-client

php-mqtt/laravel-client

Latest Stable Version Total Downloads Tests Quality Gate Status Maintainability Rating Reliability Rating Security Rating Vulnerabilities License

php-mqtt/laravel-client was created by, and is maintained by Marvin Mall. It is a Laravel wrapper for the php-mqtt/client package and allows you to connect to an MQTT broker where you can publish messages and subscribe to topics.

Installation

The package is available on packagist.org and can be installed using composer:

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

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

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:

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

Publish (QoS level 0)

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

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

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 & 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.

$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:

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:

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:

Features

This library allows you to use all the features provided by 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.

License

php-mqtt/laravel-client is open-source software licensed under the MIT license.


All versions of laravel-client with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
illuminate/config Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0|^11.0
php-mqtt/client Version ^1.3.0|^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package php-mqtt/laravel-client contains the following files

Loading the files please wait ....