Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit830f7c3

Browse files
author
LIU JIAN
authored
Merge pull request #130 from PandaLIU-1111/ping
Added ping
2 parents504648d +fae7795 commit830f7c3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎src/CommandInvoker.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class CommandInvoker
3333
*/
3434
protected$messageChannel;
3535

36+
/**
37+
* @var Channel
38+
*/
39+
private$pingChannel;
40+
3641
/**
3742
* CommandInvoker constructor.
3843
* @param Connection $connection
@@ -41,6 +46,7 @@ public function __construct(Connection $connection)
4146
{
4247
$this->connection =$connection;
4348
$this->resultChannel =newChannel();
49+
$this->pingChannel =newChannel();
4450
$this->messageChannel =newChannel(100);
4551
Coroutine::create(function ()use ($connection) {
4652
$this->receive($connection);
@@ -106,6 +112,12 @@ public function receive(Connection $connection)
106112
$buffer =null;
107113
continue;
108114
}
115+
116+
if ($type =='pong' &&count($buffer) ==5) {
117+
$this->pingChannel->push('pong');
118+
$buffer =null;
119+
continue;
120+
}
109121
}
110122
}
111123

@@ -153,6 +165,18 @@ public function interrupt()
153165
returntrue;
154166
}
155167

168+
/**
169+
* Ping
170+
* @param int $timeout
171+
* @return string
172+
* @throws \Swoole\Exception
173+
*/
174+
publicfunctionping(int$timeout =1)
175+
{
176+
$this->connection->send(Resp::build('ping'));
177+
return$this->pingChannel->pop($timeout);
178+
}
179+
156180
/**
157181
* Print error
158182
* @param \Throwable $ex

‎src/Subscriber.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,14 @@ public function close()
143143
$this->commandInvoker->interrupt();
144144
}
145145

146+
/**
147+
* Ping
148+
* @param int $timeout
149+
* @throws \Swoole\Exception
150+
*/
151+
publicfunctionping(int$timeout =1)
152+
{
153+
return$this->commandInvoker->ping($timeout);
154+
}
155+
146156
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp