memcacheMonitor_hook_sanitycheck()   A
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 24
rs 9.2222
1
<?php
2
3
declare(strict_types=1);
4
5
use Webmozart\Assert\Assert;
6
7
/**
8
 * Sanity check for memcache servers.
9
 *
10
 * This function verifies that all memcache servers work.
11
 *
12
 * @param array &$hookinfo  hookinfo
13
 */
14
function memcacheMonitor_hook_sanitycheck(array &$hookinfo): void
15
{
16
    Assert::keyExists($hookinfo, 'errors');
17
    Assert::keyExists($hookinfo, 'info');
18
19
    try {
20
        $servers = \SimpleSAML\Memcache::getRawStats();
21
    } catch (\Exception $e) {
22
        $hookinfo['errors'][] = '[memcacheMonitor] Error parsing memcache configuration: ' . $e->getMessage();
23
        return;
24
    }
25
26
    $allOK = true;
27
    foreach ($servers as $group) {
28
        foreach ($group as $server => $status) {
29
            if ($status === false) {
30
                $hookinfo['errors'][] = '[memcacheMonitor] No response from server: ' . $server;
31
                $allOK = false;
32
            }
33
        }
34
    }
35
36
    if ($allOK) {
37
        $hookinfo['info'][] = '[memcacheMonitor] All servers responding.';
38
    }
39
}
40