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