Skip to content

Commit f217ff5

Browse files
committed
Update GetKeysTrait.php
1 parent aa0a803 commit f217ff5

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/Dashboards/Memcached/MemcacheCompatibility/GetKeysTrait.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ trait GetKeysTrait {
1818
*
1919
* @param string $command
2020
*
21-
* @return array<mixed, mixed>
21+
* @return ?array<mixed, mixed>
2222
*/
23-
private function runCommand(string $command): array {
23+
private function runCommand(string $command): ?array {
2424
static $data = [];
2525

26-
$fp = fsockopen($this->server['host'], (int) $this->server['port']);
26+
$fp = @fsockopen($this->server['host'], (int) $this->server['port'], $error_code, $error_message, 3);
27+
28+
if ($fp === false) {
29+
return null;
30+
}
2731

2832
fwrite($fp, $command."\n");
2933

@@ -86,8 +90,12 @@ private function keyData(string $line): array {
8690
public function getKeys(): array {
8791
static $keys = [];
8892

89-
foreach ($this->runCommand('lru_crawler metadump all') as $line) {
90-
$keys[] = $this->keyData($line);
93+
$all_keys = $this->runCommand('lru_crawler metadump all');
94+
95+
if ($all_keys !== null) {
96+
foreach ($all_keys as $line) {
97+
$keys[] = $this->keyData($line);
98+
}
9199
}
92100

93101
return $keys;

0 commit comments

Comments
 (0)