PHP code example of immusen / yii2-swoole-mqtt

1. Go to this page and download the library: Download immusen/yii2-swoole-mqtt 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/ */

    

immusen / yii2-swoole-mqtt example snippets


php composer.phar 

# after installation, cd project root path, e.g. cd yii2-advanced-project/
mv vendor/immusen/yii2-swoole-mqtt/example/mqtt ./
mv vendor/immusen/yii2-swoole-mqtt/example/mqtt-server ./
chmod a+x ./mqtt-server
# run:
./mqtt-server
# config :
cat ./mqtt/config/params.php

return [
    'listen' => 8721,
    'daemonize' => 0,
    'auth' => 1, // config auth class in ./main.php
];
# or coding in ./mqtt/controllers/
 
    class ChannelController{
        public function actionCount($channel_id){
            echo "client {$this->fd} subscribed the count change of channel {$channel_id}";
        }
    }
  
    class ChannelController{
        public function actionJoin($channel_id, $who){
            echo "{$who} join in channel {$channel_id}";
            #then broadcast update to all client who subscribed channel 100001
            #$this->publish($fds, $sub_topic, $count);
        }
    }