|
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\Helper\TableSeparator; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
class OpcacheStatusCommand extends AbstractCommand |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
4 |
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
4 |
|
$this |
|
28
|
4 |
|
->setName('opcache:status') |
|
29
|
4 |
|
->setDescription('Show summary information about the opcode cache') |
|
30
|
4 |
|
->setHelp(''); |
|
31
|
4 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->ensureExtensionLoaded('Zend OPcache'); |
|
39
|
|
|
|
|
40
|
|
|
$info = $this->getCacheTool()->opcache_get_status(false); |
|
41
|
|
|
|
|
42
|
|
|
if ($info === false) { |
|
43
|
|
|
throw new \RuntimeException('opcache_get_status(): No Opcache status info available. Perhaps Opcache is disabled via opcache.enable or opcache.enable_cli?'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$table = new Table($output); |
|
47
|
|
|
$table->setHeaders(array('Name', 'Value')); |
|
48
|
|
|
$table->setRows($this->getRows($info, $info['opcache_statistics'])); |
|
49
|
|
|
$table->render($output); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $info |
|
54
|
|
|
* @param array $stats |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getRows($info, $stats) |
|
58
|
|
|
{ |
|
59
|
|
|
$rows = $this->getGeneralRows($info); |
|
60
|
|
|
|
|
61
|
|
|
if (isset($info['interned_strings_usage'])) { |
|
62
|
|
|
$rows = array_merge($rows, $this->getStringsRows($info)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return array_merge($rows, $this->getOpcacheStatsRows($stats)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param array $info |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getGeneralRows($info) |
|
73
|
|
|
{ |
|
74
|
|
|
return array( |
|
75
|
|
|
array('Enabled', $info['opcache_enabled'] ? 'Yes' : 'No'), |
|
76
|
|
|
array('Cache full', $info['cache_full'] ? 'Yes' : 'No'), |
|
77
|
|
|
array('Restart pending', $info['restart_pending'] ? 'Yes' : 'No'), |
|
78
|
|
|
array('Restart in progress', $info['restart_in_progress'] ? 'Yes' : 'No'), |
|
79
|
|
|
array('Memory used', Formatter::bytes($info['memory_usage']['used_memory'])), |
|
80
|
|
|
array('Memory free', Formatter::bytes($info['memory_usage']['free_memory'])), |
|
81
|
|
|
array('Memory wasted (%)', sprintf("%s (%s%%)", Formatter::bytes($info['memory_usage']['wasted_memory']), $info['memory_usage']['current_wasted_percentage'])), |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param array $info |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function getStringsRows($info) |
|
90
|
|
|
{ |
|
91
|
|
|
return array( |
|
92
|
|
|
array('Strings buffer size', Formatter::bytes($info['interned_strings_usage']['buffer_size'])), |
|
93
|
|
|
array('Strings memory used', Formatter::bytes($info['interned_strings_usage']['used_memory'])), |
|
94
|
|
|
array('Strings memory free', Formatter::bytes($info['interned_strings_usage']['free_memory'])), |
|
95
|
|
|
array('Number of strings', $info['interned_strings_usage']['number_of_strings']), |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param array $stats |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function getOpcacheStatsRows($stats) |
|
104
|
|
|
{ |
|
105
|
|
|
return array( |
|
106
|
|
|
new TableSeparator(), |
|
107
|
|
|
array('Cached scripts', $stats['num_cached_scripts']), |
|
108
|
|
|
array('Cached keys', $stats['num_cached_keys']), |
|
109
|
|
|
array('Max cached keys', $stats['max_cached_keys']), |
|
110
|
|
|
array('Start time', Formatter::date($stats['start_time'], 'U')), |
|
111
|
|
|
array('Last restart time', $stats['last_restart_time'] ? Formatter::date($stats['last_restart_time'], 'U') : 'Never'), |
|
112
|
|
|
array('Oom restarts', $stats['oom_restarts']), |
|
113
|
|
|
array('Hash restarts', $stats['hash_restarts']), |
|
114
|
|
|
array('Manual restarts', $stats['manual_restarts']), |
|
115
|
|
|
array('Hits', $stats['hits']), |
|
116
|
|
|
array('Misses', $stats['misses']), |
|
117
|
|
|
array('Blacklist misses (%)', sprintf('%s (%s%%)', $stats['blacklist_misses'], $stats['blacklist_miss_ratio'])), |
|
118
|
|
|
array('Opcache hit rate', $stats['opcache_hit_rate']), |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.