Download the PHP package php-mqtt/client without Composer

On this page you can find all versions of the php package php-mqtt/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?
php-mqtt/client
Rate from 1 - 5
Rated 3.00 based on 1 reviews

Informations about the package client

php-mqtt/client

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

php-mqtt/client was created by, and is maintained by Marvin Mall. It allows you to connect to an MQTT broker where you can publish messages and subscribe to topics. The current implementation supports all QoS levels (with limitations).

Installation

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

The package requires PHP version 8.0 or higher.

Usage

In the following, only a few very basic examples are given. For more elaborate examples, have a look at the php-mqtt/client-examples repository.

Publish

A very basic publish example using QoS 0 requires only three steps: connect, publish and disconnect

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 which reads, parses and handles messages from the broker:

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:

Client Settings

As shown in the examples above, the MqttClient takes the server, port and client id as first, second and third parameter. As fourth parameter, the protocol level can be passed. Currently supported is MQTT v3.1, available as constant MqttClient::MQTT_3_1. A fifth parameter allows passing a repository (currently, only a MemoryRepository is available by default). Lastly, a logger can be passed as sixth parameter. If none is given, a null logger is used instead.

Example:

The Logger must implement the Psr\Log\LoggerInterface.

Connection Settings

The connect() method of the MqttClient takes two optional parameters:

  1. A ConnectionSettings instance
  2. A boolean flag indicating whether a clean session should be requested (a random client id does this implicitly)

Example:

The ConnectionSettings class provides a few settings through a fluent interface. The type itself is immutable, and a new ConnectionSettings instance will be created for each added option. This also prevents changes to the connection settings after a connection has been established.

The following is a complete list of options with their respective default:

Features

Limitations

Developing & Testing

Certificates (TLS)

To run the tests (especially the TLS tests), you will need to create certificates. A command has been provided for this:

This will create all required certificates in the .ci/tls/ directory. The same script is used for continuous integration as well.

MQTT Broker for Testing

Running the tests expects an MQTT broker to be running. The easiest way to run an MQTT broker is through Docker:

When run from the project directory, this will spawn a Mosquitto MQTT broker configured with the generated TLS certificates and a custom configuration.

In case you intend to run a different broker or using a different method, or use a public broker instead, you will need to adjust the environment variables defined in phpunit.xml accordingly.

License

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


All versions of client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
psr/log Version ^1.1|^2.0|^3.0
myclabs/php-enum Version ^1.7
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/client contains the following files

Loading the files please wait ....