PHP code example of lvkai / hyperf-mqtt-client
1. Go to this page and download the library: Download lvkai/hyperf-mqtt-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lvkai / hyperf-mqtt-client example snippets
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,
]
]
];
use Hyperf\Context\ApplicationContext;
$container = ApplicationContext::getContainer();
$mqtt = $container->get(Hyperf\MqttClient\Mqtt::class);
$mqtt->publish('helloWorld', 'test');
bash
$ php bin/hyperf.php vendor:publish lvkai/hyperf-mqtt-client