Coder Social home page Coder Social logo

phpmqttclient's Introduction

PhPMqttClient

MQTT 3.1.1 Client with TSL support in PHP

Note that all calls are blocking until a timeout occurs. If you need some fancy async solution, you'll have to find another repo.

This implementation works with MQTT ver 3.1.1 for QOS levels 0 and 1. QOS level 2 should work, but is experimental until better tested.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist karpy47/php-mqtt-client

or add

"karpy47/php-mqtt-client": "*"

to the require section of your composer.json.

Requirements

Should work with all recent PHP versions.

Code developed and running in production using PHP v7.0.27 (previously also PHP v5.6.27)

Basic Usage

use karpy47\PhpMqttClient\MQTTClient;

$client = new MQTTClient('mqtt-server.domain.com', 8162);
$client->setAuthentication('mqtt-server.username','mqtt-server.password');
$client->setEncryption('cacerts.pem');
$success = $client->sendConnect(12345);  // set your client ID
if ($success) {
    $client->sendSubscribe('topic1');
    $client->sendPublish('topic2', 'Message to all subscribers of this topic');
    $messages = $client->getPublishMessages();  // now read and acknowledge all messages waiting
    foreach ($messages as $message) {
        echo $message['topic'] .': '. $message['message'] . PHP_EOL;
        // Other keys in $message array: retain (boolean), duplicate (boolean), qos (0-2), packetId (2-byte integer)
    }
    $client->sendDisconnect();    
}
$client->close();

Credits

Thanks to bluerhinos/phpMQTT and McFizh/libMQTT.

Also thanks to

License

Released under the MIT License. Please see License File for more information.

phpmqttclient's People

Contributors

karpy47 avatar tobbexiv avatar trajche avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.