Skip to content

Commit

Permalink
增加可自定义服务
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyan74 committed Mar 3, 2018
1 parent 7b40947 commit 3e5dfb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ composer require "jianyan74/yii2-websocket"
`console/config/main.php` 加入以下配置。(注意:配置在controllerMap里面)

```
'web-socket' => [
'class' => 'jianyan\websocket\WebSocketController',
'host' => '0.0.0.0',// 监听地址
'port' => 9501,// 监听端口
'config' => [// 标准的swoole配置项都可以再此加入
'daemonize' => false,// 守护进程执行
'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,
],
],
// webSocket
'web-socket' => [
'class' => 'jianyan\websocket\WebSocketController',
'server' => 'jianyan\websocket\WebSocketServer',
'host' => '0.0.0.0',// 监听地址
'port' => 9501,// 监听端口
'config' => [// 标准的swoole配置项都可以再此加入
'daemonize' => false,// 守护进程执行
'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,
],
],
```

### 使用
Expand Down
14 changes: 9 additions & 5 deletions src/WebSocketController.php → WebSocketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
use Yii;
use yii\console\Controller;
use yii\helpers\FileHelper;
use jianyan\websocket\WebSocket;

/**
* WebSocket
* 启动 php ./yii web-socket/start
* 停止 php ./yii web-socket/stop
* 重启 php ./yii web-socket/restart
*
* Class WebSocketController
* @package console\controllers
* @package jianyan\websocket
*/
class WebSocketController extends Controller
{
/**
* 实例化服务
*
* @var
*/
public $server;

/**
* 监听地址
*
Expand Down Expand Up @@ -75,7 +79,7 @@ public function actionStart()
$this->setPid();

// 运行
$ws = new WebSocket($this->host, $this->port, $this->mode, $this->socketType, $this->config);
$ws = new $this->server($this->host, $this->port, $this->mode, $this->socketType, $this->config);
$ws->run();

$this->stdout("服务正在运行,监听 {$this->host}:{$this->port}" . PHP_EOL);
Expand Down
File renamed without changes.

0 comments on commit 3e5dfb1

Please sign in to comment.