PHP code example of jianyan74 / yii2-websocket

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

    

jianyan74 / yii2-websocket example snippets


// webSocket
'websocket' => [
    'class' => 'jianyan\websocket\console\WebSocketController',
    'server' => 'jianyan\websocket\server\WebSocketServer', // 可替换为自己的业务类继承该类即可
    'host' => '0.0.0.0',// 监听地址
    'port' => 9501,// 监听端口
    'type' => 'ws', // 默认为ws连接,可修改为wss
    'config' => [// 标准的swoole配置项都可以再此加入
        'daemonize' => false,// 守护进程执行
        'task_worker_num' => 4,//task进程的数量
        // 'ssl_cert_file' => '',
        // 'ssl_key_file' => '',
        'pid_file' => __DIR__ . '/../../backend/runtime/logs/server.pid',
        'log_file' => __DIR__ . '/../../backend/runtime/logs/swoole.log',
        'log_level' => 0,
    ],
],
 

  # 启动 
  php ./yii websocket/start
  # 停止 
  php ./yii websocket/stop
  # 重启 
  php ./yii websocket/restart