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

25 lines
728 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use Workerman\Worker;
use Workerman\Timer;
$worker = new Worker();
$worker->onWorkerStart = function(){
$mqtt = new Workerman\Mqtt\Client('mqtts://test.mosquitto.org:8883', array(
'ssl' => array(
'local_cert' => __DIR__ . '/ssl/mosquitto.org.crt',
'local_pk' => __DIR__ . '/ssl/mosquitto.org.key',
'verify_peer' => false,
),
'debug' => true
));
$mqtt->onConnect = function($mqtt) {
// publish message every 2 seconds.
Timer::add(2, function() use ($mqtt) {
$mqtt->publish('workerman', 'hello workerman mqtt');
});
};
$mqtt->connect();
};
Worker::runAll();