zhangxiuyu/laravel-mqtt

This is mqtt

v1.0.1 2020-07-28 08:20 UTC

This package is auto-updated.

Last update: 2022-09-10 11:54:10 UTC


README

Simps License PHP Version Swoole Version

使用样例:

$config = [
    'ip' => '0.0.0.0',
    'port' => 8080,
    'callbacks' => [
    ],
    'receiveCallbacks' => [
        \Mqtt\server\MQTT::CONNECT => [\Mqtt\MqttServer::class, 'onMqConnect'],
        \Mqtt\server\MQTT::PINGREQ => [\Mqtt\MqttServer::class, 'onMqPingreq'],
        \Mqtt\server\MQTT::DISCONNECT => [\Mqtt\MqttServer::class, 'onMqDisconnect'],
        \Mqtt\server\MQTT::PUBLISH => [\Mqtt\MqttServer::class, 'onMqPublish'],
        \Mqtt\server\MQTT::SUBSCRIBE => [\Mqtt\MqttServer::class, 'onMqSubscribe'],
        \Mqtt\server\MQTT::UNSUBSCRIBE => [\Mqtt\MqttServer::class, 'onMqUnsubscribe'],
    ],
    'settings' => [
        'worker_num' => 1,
        'open_mqtt_protocol' => true,
    ],
];

Mqtt\AppServer::run($config);

效果:

root@5ef6b759adf0:/var/www/PHP/laravel-MQTT/src/mqtt# php Test.php mqtt:start
                  _   _   
                 | | | |  
  _ __ ___   __ _| |_| |_ 
 | '_ ` _ \ / _` | __| __|
 | | | | | | (_| | |_| |_ 
 |_| |_| |_|\__, |\__|\__|
               | |        
               |_|           Version: 1.0.3
[2020-07-24 17:20:40] [INFO] Swoole MQTT Server running:mqtt://0.0.0.0:8080

安装

可以通过 composer 进行安装。

$ composer require zhangxiuyu/laravel-mqtt

demo在 项目 server/Test.php 文件中 可以根据文件配置 对象

最后执行你的文件即可, 建议放在项目的bin 目录中 命令: php bin/xxx.php mqtt:start