In this example, we provide the sample code for connecting to MQTT Broker through TCP and TLS protocols.
The example selects the client library php-mqtt/client
with the most downloads on composer, and there are also some other excellent libraries based on Swoole that welcome everyone to use it and submit the sample and list to it.
For more documentation about php-mqtt/client, please refer to Packagist php-mqtt/client.
PHP 7.4 or later
composer require php-mqtt/client
php pubsub_tcp.php