Skip to content

Commit

Permalink
Squashed 'src/websocket-server/' changes from d614189..a463143
Browse files Browse the repository at this point in the history
a463143 fix: ws server push method param is error (#186)
a8a91ad Upstream travis ci config (#160)
b6a8e59 修复Json Validator会失效的BUG (#153)
93113b0 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)

git-subtree-dir: src/websocket-server
git-subtree-split: a46314397916c28553ffff73c61985e0e2635ebd
  • Loading branch information
swoft-bot committed Oct 6, 2018
1 parent e7a14a0 commit 27d4bbd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ language: php
php:
- 7.0
- 7.1

services:
- mysql

before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- 7.2

install:
- wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz -O hiredis.tar.gz && mkdir -p hiredis && tar -xf hiredis.tar.gz -C hiredis --strip-components=1 && cd hiredis && sudo make -j$(nproc) && sudo make install && sudo ldconfig && cd ..
- pecl install -f swoole-2.1.1
- wget https://github.com/swoole/swoole-src/archive/v4.0.2.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure && make -j$(nproc) && make install && cd -
- echo "extension = swoole.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

before_script:
- phpenv config-rm xdebug.ini
- composer update

script: composer test
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
"url": "https://packagist.laravel-china.org"
}
},
"require-dev": {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/WsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function stop()
$serverOpts = $server->getServerSetting();
$pidFile = $serverOpts['pfile'];

@unlink($pidFile);
\output()->writeln(sprintf('<info>Swoft %s is stopping ...</info>', input()->getScript()));

$result = $server->stop();
Expand All @@ -129,6 +128,8 @@ public function stop()
if (!$result) {
\output()->writeln(sprintf('<error>Swoft %s stop fail</error>', input()->getScript()), true, true);
}
//删除pid文件
@unlink($pidFile);

\output()->writeln(sprintf('<success>Swoft %s stop success!</success>', input()->getScript()));
}
Expand Down
14 changes: 9 additions & 5 deletions src/WebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,21 @@ public function log(string $msg, array $data = [], string $type = 'info')
/**
* @param string $fd
* @param string $data
* @param bool $isBinary
* @param int $opcode The data type.
* allow:
* WEBSOCKET_OPCODE_TEXT = 1
* WEBSOCKET_OPCODE_BINARY = 2
* WEBSOCKET_OPCODE_PING = 9
* @param bool $finish
* @return bool
*/
public function push(string $fd, string $data, $isBinary = false, bool $finish = true): bool
public function push(string $fd, string $data, int $opcode = 1, bool $finish = true): bool
{
if (!$this->server->exist($fd)) {
return false;
}

return $this->server->push($fd, $data, $isBinary, $finish);
return $this->server->push($fd, $data, $opcode, $finish);
}

/**
Expand Down Expand Up @@ -164,11 +168,11 @@ public function send(string $data, $receivers = 0, $excluded = 0, int $sender =
* @param int $sender 发送者 fd
* @return int
*/
public function sendTo(int $receiver, string $data, int $sender = 0): int
public function sendTo(int $receiver, string $data, int $sender = -1): int
{
$finish = true;
$opcode = 1;
$fromUser = $sender < 1 ? 'SYSTEM' : $sender;
$fromUser = $sender < 0 ? 'SYSTEM' : $sender;

$this->log("(private)The #{$fromUser} send message to the user #{$receiver}. Data: {$data}");

Expand Down

0 comments on commit 27d4bbd

Please sign in to comment.