PHP code example of kriss / yii2-web-msg-sender

1. Go to this page and download the library: Download kriss/yii2-web-msg-sender 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/ */

    

kriss / yii2-web-msg-sender example snippets



use kriss\webMsgSender\WebMsgSender;

return [
    'components' => [
        // others
        WebMsgSender::COMPONENT_NAME => [
            'class' => WebMsgSender::class,
            // config see WebMsgSender public attributes
            // change like this
            //'socketPort' => 2123
        ],
    ],
];


return [
    'controllerMap' => [
        'web-msg-sender-service' => [
            'class' => \kriss\webMsgSender\ServiceController::class,
        ],
    ],
];

<?= \kriss\webMsgSender\ClientReceiveWidget::widget(['uid' => Yii::$app->user->id]) 


use kriss\webMsgSender\WebMsgSender;
use yii\helpers\Html;

WebMsgSender::getComponent()->getSender()->sendInfo('You Have A Message,' . Html::a('[clickMe]', 'http://www.baidu.com'));

use kriss\webMsgSender\WebMsgSender;

return [
    'components' => [
        // others
        WebMsgSender::COMPONENT_NAME => [
            'class' => WebMsgSender::class,
            // others
            'socketOpts' => [
                'ssl' => [
                    'local_cert'  => __DIR__ . '/local-ssl.test.pem', // absolute path
                    'local_pk'    => __DIR__ . '/local-ssl.test.key',
                    'verify_peer' => false,
                ],
            ],
            'receiveSocketUrl' => 'https://local-ssl.test:{port}', // domain must match ssl cert
        ],
    ],
];
bash
php yii web-msg-sender-service/start
conf
server {
  listen 443;

  ssl on;
  ssl_certificate /etc/ssl/local-ssl.test.pem;
  ssl_certificate_key /etc/ssl/local-ssl.test.key;
  ssl_session_timeout 5m;
  ssl_session_cache shared:SSL:50m;
  ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

  location /socket.io
  {
    proxy_pass http://127.0.0.1:2120;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
  }
}