在webman中自定义进程使用mqtt的订阅,为何提示Error: Class 'process\Workerman\Mqtt\Client' not found in D:\zpxprom\gitee\workman\zpx-mqtt_api\process\MqttTask.php:11

zhang

这个自定义进程为何老提示Error: Class 'process\Workerman\Mqtt\Client' not found
namespace process;
use Workerman\Worker;
class MqttTask
{
public function onWorkerStart()
{
$mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:1883', array(
'debug' => true,
"username"=>"admin", "password"=>"u123",
));
$mqtt->onConnect = function($mqtt) {
$mqtt->subscribe('zipcodexpress/sub');
};
$mqtt->onMessage = function($topic, $content){
echo "topic:$topic content:$content\n";
};
$mqtt->connect();
}

}

1256 1 0
1个回答

roczyl

没找到 Workerman\Mqtt\Client 这个类
改成 \Workerman\Mqtt\Client 试试

  • zhang 2022-08-28

    解决了谢谢,$mqtt = new \Workerman\Mqtt\Client这样写就可以了

年代过于久远,无法发表回答
×
🔝