Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 35a31b6

Browse files
committed
Prevent Apc* checks' fatal error with APC extension missing, remove CLI check, cleanup.
1 parent 9624569 commit 35a31b6

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/ZendDiagnostics/Check/ApcFragmentation.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Checks to see if the APC fragmentation is below warning/critical thresholds
1616
*
1717
* APC memory logic borrowed from APC project:
18+
*
1819
* https://github.com/php/pecl-caching-apc/blob/master/apc.php
1920
* authors: Ralf Becker <[email protected]>, Rasmus Lerdorf <[email protected]>, Ilia Alshanetsky <[email protected]>
2021
* license: The PHP License, version 3.01
@@ -37,8 +38,8 @@ class ApcFragmentation extends AbstractCheck implements CheckInterface
3738
protected $criticalThreshold;
3839

3940
/**
40-
* @param int $warningThreshold A number between 0 and 100
41-
* @param int $criticalThreshold A number between 0 and 100
41+
* @param int $warningThreshold A number between 0 and 100
42+
* @param int $criticalThreshold A number between 0 and 100
4243
* @throws InvalidArgumentException
4344
*/
4445
public function __construct($warningThreshold, $criticalThreshold)
@@ -71,11 +72,14 @@ public function __construct($warningThreshold, $criticalThreshold)
7172
*/
7273
public function check()
7374
{
74-
if ('cli' === php_sapi_name()) {
75-
return new Skip('APC not available in CLI');
75+
if (!function_exists('apc_sma_info')) {
76+
return new Warning('APC extension is not available');
77+
}
78+
79+
if (!$info = apc_sma_info()) {
80+
return new Warning('Unable to retrieve APC memory status information.');
7681
}
7782

78-
$info = apc_sma_info();
7983
$nseg = $freeseg = $fragsize = $freetotal = 0;
8084

8185
for ($i = 0; $i < $info['num_seg']; $i++) {

src/ZendDiagnostics/Check/ApcMemory.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ApcMemory extends AbstractCheck implements CheckInterface
3737
protected $criticalThreshold;
3838

3939
/**
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
4242
* @throws InvalidArgumentException
4343
*/
4444
public function __construct($warningThreshold, $criticalThreshold)
@@ -59,8 +59,8 @@ public function __construct($warningThreshold, $criticalThreshold)
5959
throw new InvalidArgumentException('Invalid criticalThreshold argument - expecting an integer between 1 and 100');
6060
}
6161

62-
$this->warningThreshold = (int) $warningThreshold;
63-
$this->criticalThreshold = (int) $criticalThreshold;
62+
$this->warningThreshold = (int)$warningThreshold;
63+
$this->criticalThreshold = (int)$criticalThreshold;
6464
}
6565

6666
/**
@@ -71,16 +71,19 @@ public function __construct($warningThreshold, $criticalThreshold)
7171
*/
7272
public function check()
7373
{
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');
7676
}
7777

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;
8285
$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));
8487

8588
if ($percentUsed > $this->criticalThreshold) {
8689
return new Failure($message);

0 commit comments

Comments
 (0)