Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7825efb

Browse files
Ensure we're talking to redis-server in our high ports test.
Instead of just checking whether or not something is listening on the high ports, send a quick PING to make sure. We're not just using another Redis instance because the point of the test is to protect against a regression when connecting to high port numbers.
1 parent 5f6ce41 commit 7825efb

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tests/RedisTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7323,22 +7323,31 @@ public function testUnixSocket() {
73237323
}
73247324
}
73257325

7326+
protected function detectRedis($host, $port) {
7327+
$sock = @fsockopen($host, $port, $errno, $errstr, .1);
7328+
if (! $sock)
7329+
return false;
7330+
7331+
stream_set_timeout($sock, 0, 100000);
7332+
7333+
$ping_cmd = "*1\r\n$4\r\nPING\r\n";
7334+
if (fwrite($sock, $ping_cmd) != strlen($ping_cmd))
7335+
return false;
7336+
7337+
return fread($sock, strlen("+PONG\r\n")) == "+PONG\r\n";
7338+
}
7339+
73267340
/* Test high ports if we detect Redis running there */
73277341
public function testHighPorts() {
7328-
$arr_ports = [32767, 32768, 32769];
7329-
$arr_test_ports = [];
7330-
7331-
foreach ($arr_ports as $port) {
7332-
if (is_resource(@fsockopen('localhost', $port))) {
7333-
$arr_test_ports[] = $port;
7334-
}
7335-
}
7342+
$ports = array_filter(array_map(function ($port) {
7343+
return $this->detectRedis('localhost', $port) ? $port : 0;
7344+
}, [32768, 32769, 32770]));
73367345

7337-
if ( ! $arr_test_ports) {
7346+
if ( ! $ports) {
73387347
return $this->markTestSkipped();
73397348
}
73407349

7341-
foreach ($arr_test_ports as $port) {
7350+
foreach ($ports as $port) {
73427351
$obj_r = new Redis();
73437352
try {
73447353
@$obj_r->connect('localhost', $port);

0 commit comments

Comments
 (0)