zoukankan      html  css  js  c++  java
  • mqtt mosquitto-php 安装笔记

    https://mosquitto-php.readthedocs.io/en/latest/overview.html

    Requirements

    • PHP 5.3 or newer, including PHP 7+
    • libmosquitto 1.2.x or later

    Installation

    If you’ve used a pre-built package to install Mosquitto, you need to make sure you have the development headers installed. On Red Hat-derived systems, this is probably called libmosquitto-devel, and on Debian-based systems it will be libmosquitto-dev.

    You may obtain this package using PECL:

    pecl install Mosquitto-alpha
    

    Alternatively, you can use the normal extension build process:

    phpize
    ./configure --with-mosquitto=/path/to/libmosquitto
    make
    make install
    

    Then add extension=mosquitto.so to your php.ini.

    The --with-mosquitto argument is optional, and only required if your libmosquitto install cannot be found.

    General Operation

    The underlying library is based on callbacks and event-driven operation. As such, you have to call the loop() method of the Client frequently to permit the library to handle the messages in its queues. You can use loopForever() to ensure that the client handles this itself. Also, you should use the callback functions to ensure that you only attempt to publish after the client has connected, etc. For example, here is how you would correctly publish a QoS=2 message:

    <?php
    
    $c = new MosquittoClient;
    $c->onConnect(function() use ($c) {
        $c->publish('mgdm/test', 'Hello', 2);
        $c->disconnect();
    });
    
    $c->connect('test.mosquitto.org');
    
    // Loop around to permit the library to do its work
    // This function will call the callback defined in `onConnect()`
    // and disconnect cleanly when the message has been sent
    $c->loopForever();
    
    echo "Finished
    ";
  • 相关阅读:
    linux ssh 免密码登录
    Emacs Org Mode学习
    Emacs Org Mode学习
    java--for循环,一个分号的区别
    java--for循环,一个分号的区别
    【JVM.6】虚拟机类加载机制
    【JVM.5】类文件结构
    【JVM.4】调优案例分析与实战
    【JVM.3】虚拟机性能监控与故障处理工具
    【JVM.2】垃圾收集器与内存分配策略
  • 原文地址:https://www.cnblogs.com/xiami2046/p/13570227.html
Copyright © 2011-2022 走看看