PHPackages                             233cy/hyperf-mqtt-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. 233cy/hyperf-mqtt-client

ActiveLibrary

233cy/hyperf-mqtt-client
========================

1.0.1(1y ago)026MITPHPPHP &gt;=8.0

Since Mar 22Pushed 1y agoCompare

[ Source](https://github.com/233cy/hyperf-mqtt-client)[ Packagist](https://packagist.org/packages/233cy/hyperf-mqtt-client)[ RSS](/packages/233cy-hyperf-mqtt-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (0)

安装
--

[](#安装)

```
$ composer require lvkai/hyperf-mqtt-client
```

配置项
---

[](#配置项)

配置项类型默认值备注hoststring'localhost'MQTT地址portint1883MQTT端口user\_namestring无用户名passwordstring无密码keep\_aliveint60保活时间protocolstring3.1.1mqtt协议版本repositorystring\\PhpMqtt\\Client\\Repositories\\MemoryRepository::class仓储对象,默认内存clean\_sessionbooletrue会话清除poolobject{}连接池配置```
return [
    'default' => [
        'host'          => env('MQTT_HOST', 'localhost'),
        'port'          => (int)env('MQTT_PORT', 1883),
        'client_id'     => env('MQTT_CLIENT_ID', ''),
        'user_name'     => env('MQTT_USERNAME', ''),
        'password'      => env('MQTT_PASSWORD', ''),
        'keep_alive'    => env('MQTT_KEEP_ALIVE', 20),
        'protocol'      => \PhpMqtt\Client\MqttClient::MQTT_3_1_1,
        'repository'    => \PhpMqtt\Client\Repositories\MemoryRepository::class,
        'clean_session' => true,
        'pool'          => [
            'min_connections' => 1,
            'max_connections' => 10,
            'connect_timeout' => 10.0,
            'waitTimeout'     => 3.0,
            'heartbeat'       => -1,
            'maxIdleTime'     => env('MQTT_KEEP_ALIVE', 20) * 1.5,
        ]
    ]
];
```

`publish`完整配置文件使用命令

```
$ php bin/hyperf.php vendor:publish lvkai/hyperf-mqtt-client
```

使用
--

[](#使用)

`lvkai/hyperf-mqtt-client`实现了`php-mqtt/client`代理和连接池，用户可以直接通过依赖注入`\Hyperf\Mqttclient\Mqtt`来使用mqtt客户端，实际获取的是一个`\PhpMqtt\Client\MqttClient`的一个代理对象.

```
