phpmqtt ssl tls使用证书 cafile 文件 连接服务器

其它语言的mqttclient

https://www.eclipse.org/paho/downloads.php

1.安装phpmqtt

-----------------------

`composer require bluerhinos/phpmqtt`

2.引入并使用


phpmqtt ssl tls使用证书 cafile 文件 连接服务器_第1张图片

require("phpMQTT.php");

$server ="127.0.0.1";    // change if necessary

$port =8883;                    // change if necessary

$username ="";                  // set your username

$password ="";                  // set your password

$client_id ="phpMQTT-publisher"; // make sure this is unique for connecting to sever - you could use uniqid()

$mqtt =new phpMQTT($server, $port, $client_id, 'cert/ca.crt');

if ($mqtt->connect(true)) {

$mqtt->publish("bluerhinos/phpMQTT/examples/publishtest", "Hello World! at " . date("r"), 0);

  $mqtt->close();

}else {

echo "Time out!\n";

}


//如果不能连接上,改一下phpMQTT.php中的参数 83行 verify_peer_name为false


phpmqtt ssl tls使用证书 cafile 文件 连接服务器_第2张图片

你可能感兴趣的:(phpmqtt ssl tls使用证书 cafile 文件 连接服务器)