|
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 OpcacheStatusScriptsCommand extends AbstractCommand |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
4 |
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
4 |
|
$this |
|
27
|
4 |
|
->setName('opcache:status:scripts') |
|
28
|
4 |
|
->setDescription('Show scripts in the opcode cache') |
|
29
|
4 |
|
->setHelp(''); |
|
30
|
4 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->ensureExtensionLoaded('Zend OPcache'); |
|
38
|
|
|
|
|
39
|
|
|
$info = $this->getCacheTool()->opcache_get_status(true); |
|
40
|
|
|
|
|
41
|
|
|
if ($info === false) { |
|
42
|
|
|
throw new \RuntimeException('opcache_get_status(): No Opcache status info available. Perhaps Opcache is disabled via opcache.enable or opcache.enable_cli?'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$table = new Table($output); |
|
46
|
|
|
$table |
|
47
|
|
|
->setHeaders(array( |
|
48
|
|
|
'Hits', |
|
49
|
|
|
'Memory', |
|
50
|
|
|
'Filename' |
|
51
|
|
|
)) |
|
52
|
|
|
->setRows($this->processFilelist($info['scripts'])) |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$table->render($output); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function processFileList(array $cacheList) |
|
59
|
|
|
{ |
|
60
|
|
|
$list = array(); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($cacheList as $item) { |
|
63
|
|
|
$list[] = array( |
|
64
|
|
|
number_format($item['hits']), |
|
65
|
|
|
Formatter::bytes($item['memory_consumption']), |
|
66
|
|
|
$this->processFilename($item['full_path']), |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $list; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function processFilename($filename) |
|
74
|
|
|
{ |
|
75
|
|
|
$dir = getcwd(); |
|
76
|
|
|
|
|
77
|
|
|
if (0 === strpos($filename, $dir)) { |
|
78
|
|
|
return "." . substr($filename, strlen($dir)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $filename; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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.