Skip to content

Commit 7ccc4ce

Browse files
author
epriestley
committedJan 12, 2017
With APCu 5+, use apcu_* function to examine cache state
Summary: Ref T9640. APCu 5.0+ (for PHP7) uses `apcu_*` functions instead of `apc_` functions. Test for function existence and call the appropriate functions. Test Plan: {F2352695} Reviewers: chad Reviewed By: chad Maniphest Tasks: T9640 Differential Revision: https://secure.phabricator.com/D17198
1 parent a2cd3d9 commit 7ccc4ce

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed
 

‎src/applications/cache/spec/PhabricatorDataCacheSpec.php

+31-19
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,40 @@ private function initNoneSpec() {
7979
}
8080

8181
private function initAPCCommonSpec() {
82-
$mem = apc_sma_info();
83-
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
82+
$state = array();
8483

85-
$info = apc_cache_info('user');
86-
$this->setUsedMemory($info['mem_size']);
87-
$this->setEntryCount(count($info['cache_list']));
84+
if (function_exists('apcu_sma_info')) {
85+
$mem = apcu_sma_info();
86+
$info = apcu_cache_info();
87+
} else if (function_exists('apc_sma_info')) {
88+
$mem = apc_sma_info();
89+
$info = apc_cache_info('user');
90+
} else {
91+
$mem = null;
92+
}
8893

89-
$cache = $info['cache_list'];
90-
$state = array();
91-
foreach ($cache as $item) {
92-
$info = idx($item, 'info', '<unknown-key>');
93-
$key = self::getKeyPattern($info);
94-
if (empty($state[$key])) {
95-
$state[$key] = array(
96-
'max' => 0,
97-
'total' => 0,
98-
'count' => 0,
99-
);
94+
if ($mem) {
95+
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
96+
97+
$this->setUsedMemory($info['mem_size']);
98+
$this->setEntryCount(count($info['cache_list']));
99+
100+
$cache = $info['cache_list'];
101+
$state = array();
102+
foreach ($cache as $item) {
103+
$info = idx($item, 'info', '<unknown-key>');
104+
$key = self::getKeyPattern($info);
105+
if (empty($state[$key])) {
106+
$state[$key] = array(
107+
'max' => 0,
108+
'total' => 0,
109+
'count' => 0,
110+
);
111+
}
112+
$state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
113+
$state[$key]['total'] += $item['mem_size'];
114+
$state[$key]['count']++;
100115
}
101-
$state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
102-
$state[$key]['total'] += $item['mem_size'];
103-
$state[$key]['count']++;
104116
}
105117

106118
$this->setCacheSummary($state);

0 commit comments

Comments
 (0)
Failed to load comments.