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

Commitce3b7f7

Browse files
committed
Added ping
1 parentd582215 commitce3b7f7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

‎src/CommandInvoker.php‎

Lines changed: 23 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);
@@ -63,6 +69,11 @@ public function receive(Connection $connection)
6369
}
6470
$line =substr($line,0, -(strlen(static::CRLF)));
6571

72+
if ($line =='pong') {
73+
$this->pingChannel->push($line);
74+
continue;
75+
}
76+
6677
if ($line =='+OK') {
6778
$this->resultChannel->push($line);
6879
continue;
@@ -153,6 +164,18 @@ public function interrupt()
153164
returntrue;
154165
}
155166

167+
/**
168+
* Ping
169+
* @param int $timeout
170+
* @return string
171+
* @throws \Swoole\Exception
172+
*/
173+
publicfunctionping(int$timeout =1)
174+
{
175+
$this->connection->send(Resp::build('ping'));
176+
return$this->pingChannel->pop($timeout);
177+
}
178+
156179
/**
157180
* Print error
158181
* @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