1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of CacheTool. |
5
|
|
|
* |
6
|
|
|
* (c) Samuel Gordalina <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CacheTool\Command; |
13
|
|
|
|
14
|
|
|
use CacheTool\Util\Formatter; |
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
class ApcuCacheInfoCommand extends AbstractCommand |
20
|
|
|
{ |
21
|
|
|
protected static $apcFix = [ |
22
|
|
|
'stime' => "start_time", |
23
|
|
|
'atime' => "access_time", |
24
|
|
|
'mtime' => "modification_time", |
25
|
|
|
'ctime' => "creation_time", |
26
|
|
|
'dtime' => "deletion_time", |
27
|
|
|
|
28
|
|
|
'nslots' => "num_slots", |
29
|
|
|
'nhits' => "num_hits", |
30
|
|
|
'nmisses' => "num_misses", |
31
|
|
|
'ninserts' => "num_inserts", |
32
|
|
|
'nentries' => "num_entries", |
33
|
|
|
'nexpunges' => "expunges", |
34
|
|
|
"num_expunges" => "expunges", |
35
|
|
|
|
36
|
|
|
'key' => "info", |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
19 |
|
protected function configure() |
43
|
|
|
{ |
44
|
|
|
$this |
45
|
19 |
|
->setName('apcu:cache:info') |
46
|
19 |
|
->setDescription('Shows APCu user & system cache information') |
47
|
19 |
|
->setHelp(''); |
48
|
19 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
54
|
|
|
{ |
55
|
1 |
|
$this->ensureExtensionLoaded('apcu'); |
56
|
|
|
|
57
|
1 |
|
$info = $this->getCacheTool()->apcu_cache_info(true); |
58
|
|
|
|
59
|
1 |
|
$this->normalize($info); |
60
|
|
|
|
61
|
1 |
|
if (empty($info)) { |
62
|
|
|
throw new \RuntimeException("Could not fetch info from APCu"); |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
$table = new Table($output); |
66
|
1 |
|
$table->setHeaders(['Name', 'Info']); |
67
|
1 |
|
$table->setRows($this->getRows($info)); |
68
|
1 |
|
$table->render($output); |
|
|
|
|
69
|
|
|
|
70
|
1 |
|
return 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $info |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
1 |
|
protected function getRows($info) |
78
|
|
|
{ |
79
|
|
|
// missing: cache_list, deleted_list, slot_distribution |
80
|
|
|
return [ |
81
|
1 |
|
['Slots', $info['num_slots']], |
82
|
1 |
|
['TTL', $info['ttl']], |
83
|
1 |
|
['Hits', number_format($info['num_hits'])], |
84
|
1 |
|
['Misses', number_format($info['num_misses'])], |
85
|
1 |
|
['Inserts', number_format($info['num_inserts'])], |
86
|
1 |
|
['Expunges', number_format($info['expunges'])], |
87
|
1 |
|
['Start time', Formatter::date($info['start_time'], 'U')], |
88
|
1 |
|
['Memory size', Formatter::bytes($info['mem_size'])], |
89
|
1 |
|
['Entries', number_format($info['num_entries'])], |
90
|
1 |
|
['File upload progress', ini_get('apcu.rfc1867') ? 'Yes' : 'No'], |
91
|
1 |
|
['Memory type', $info['memory_type']], |
92
|
1 |
|
['Locking type', $info['locking_type'] ?? 'Not Supported'], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Fix inconsistencies between APC and APCu |
98
|
|
|
* |
99
|
|
|
* @param array &$array |
100
|
|
|
*/ |
101
|
2 |
|
protected function normalize(array &$array) |
102
|
|
|
{ |
103
|
2 |
|
foreach ($array as $key => $value) { |
104
|
2 |
|
if (array_key_exists($key, self::$apcFix)) { |
105
|
|
|
unset($array[$key]); |
106
|
|
|
$array[self::$apcFix[$key]] = $value; |
107
|
|
|
} |
108
|
|
|
} |
109
|
2 |
|
} |
110
|
|
|
} |
111
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.