PHP code example of oliverlorenz / php-mqtt-client

1. Go to this page and download the library: Download oliverlorenz/php-mqtt-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oliverlorenz / php-mqtt-client example snippets


$config = or = ClientFactory::createClient(new Version4());

$p = $connector->create($config['server'], $config['port'], $config['options']);
$p->then(function(Stream $stream) use ($connector) {
    return $connector->publish($stream, 'a/b', 'example message');
});
$connector->getLoop()->run();

$config = or = ClientFactory::createClient(new Version4());

$p = $connector->create($config['server'], $config['port'], $config['options']);
$p->then(function(\React\Stream\Stream $stream) use ($connector) {
    $stream->on(Publish::EVENT, function(Publish $message) {
        print_r($message);
    });
    
    $connector->subscribe($stream, 'a/b', 0);
    $connector->subscribe($stream, 'a/c', 0);
});

$connector->getLoop()->run();