iot-admin/vendor/workerman/mqtt/examples/subscribe-no-ssl.php
2023-11-30 22:53:01 +08:00

20 lines
529 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use Workerman\Worker;
$worker = new Worker();
$worker->onWorkerStart = function(){
$mqtt = new Workerman\Mqtt\Client('mqtt://broker.emqx.io:1883', array(
'debug' => true,
"username"=>"rw", "password"=>"readwrite"
));
$mqtt->onConnect = function($mqtt) {
$mqtt->subscribe('workerman');
};
$mqtt->onMessage = function($topic, $content){
echo "topic:$topic content:$content\n";
};
$mqtt->connect();
};
Worker::runAll();