@@ -37,8 +37,8 @@ class ApcMemory extends AbstractCheck implements CheckInterface
37
37
protected $ criticalThreshold ;
38
38
39
39
/**
40
- * @param int $warningThreshold A number between 0 and 100
41
- * @param int $criticalThreshold A number between 0 and 100
40
+ * @param int $warningThreshold A number between 0 and 100
41
+ * @param int $criticalThreshold A number between 0 and 100
42
42
* @throws InvalidArgumentException
43
43
*/
44
44
public function __construct ($ warningThreshold , $ criticalThreshold )
@@ -59,8 +59,8 @@ public function __construct($warningThreshold, $criticalThreshold)
59
59
throw new InvalidArgumentException ('Invalid criticalThreshold argument - expecting an integer between 1 and 100 ' );
60
60
}
61
61
62
- $ this ->warningThreshold = (int ) $ warningThreshold ;
63
- $ this ->criticalThreshold = (int ) $ criticalThreshold ;
62
+ $ this ->warningThreshold = (int )$ warningThreshold ;
63
+ $ this ->criticalThreshold = (int )$ criticalThreshold ;
64
64
}
65
65
66
66
/**
@@ -71,16 +71,19 @@ public function __construct($warningThreshold, $criticalThreshold)
71
71
*/
72
72
public function check ()
73
73
{
74
- if (' cli ' === php_sapi_name ( )) {
75
- return new Skip ('APC not available in CLI ' );
74
+ if (! function_exists ( ' apc_sma_info ' )) {
75
+ return new Warning ('APC extension is not available ' );
76
76
}
77
77
78
- $ info = apc_sma_info ();
79
- $ size = $ info ['num_seg ' ] * $ info ['seg_size ' ];
80
- $ available = $ info ['avail_mem ' ];
81
- $ used = $ size - $ available ;
78
+ if (!$ info = apc_sma_info ()) {
79
+ return new Warning ('Unable to retrieve APC memory status information. ' );
80
+ }
81
+
82
+ $ size = $ info ['num_seg ' ] * $ info ['seg_size ' ];
83
+ $ available = $ info ['avail_mem ' ];
84
+ $ used = $ size - $ available ;
82
85
$ percentUsed = ($ used / $ size ) * 100 ;
83
- $ message = sprintf ('%.0f%% of available %s memory used. ' , $ percentUsed , $ this ->formatBytes ($ size ));
86
+ $ message = sprintf ('%.0f%% of available %s memory used. ' , $ percentUsed , $ this ->formatBytes ($ size ));
84
87
85
88
if ($ percentUsed > $ this ->criticalThreshold ) {
86
89
return new Failure ($ message );
0 commit comments