• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gordalina / cachetool / 21418036912

27 Jan 2026 11:16PM UTC coverage: 91.631% (+1.2%) from 90.476%
21418036912

Pull #263

github

web-flow
Merge 519d4b6a4 into 732a831d5
Pull Request #263: Bump phpunit/phpunit from 9.5.25 to 9.6.33

1062 of 1159 relevant lines covered (91.63%)

124.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.36
/src/Command/OpcacheStatusCommand.php
1
<?php
2

3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <samuel.gordalina@gmail.com>
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 AbstractOpcacheCommand
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        $this
400✔
28
            ->setName('opcache:status')
400✔
29
            ->setDescription('Show summary information about the opcode cache')
400✔
30
            ->setHelp('');
400✔
31
    }
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function execute(InputInterface $input, OutputInterface $output): int
37
    {
38
        $this->ensureExtensionLoaded('Zend OPcache');
10✔
39

40
        $info = $this->getCacheTool()->opcache_get_status(false);
10✔
41
        try {
42

43
            $this->ensureSuccessfulOpcacheCall($info);
10✔
44
        } catch (\RuntimeException $e) {
×
45
            // lets handle gracefully when file_cache_only is true
46
            if (!strstr($e->getMessage(), 'opcache.file_cache_only')) {
×
47
                throw $e;
×
48
            }
49
        }
50

51
        if ($info['file_cache_only'] ?? false) {
10✔
52
            $this->renderFileCacheOnlyMode($output, $info);
×
53
        } else {
54
            $this->render($output, $info);
10✔
55
        }
56

57
        return 0;
10✔
58
    }
59

60
    /**
61
     * @param  OutputInterface $output
62
     * @param  array $info
63
     */
64
    protected function renderFileCacheOnlyMode(OutputInterface $output, $info) {
65
        $iterator = function ($k) use (&$info) {
×
66
            return [$k, var_export($info[$k], true)];
×
67
        };
×
68

69
        $table = new Table($output);
×
70
        $table->setHeaders(['Name', 'Value']);
×
71
        $table->setRows(array_map($iterator, array_keys($info)));
×
72
        $table->render();
×
73
    }
74

75
    /**
76
     * @param  OutputInterface $output
77
     * @param  array $info
78
     */
79
    protected function render(OutputInterface $output, $info) {
80
        $table = new Table($output);
10✔
81
        $table->setHeaders(['Name', 'Value']);
10✔
82
        $table->setRows($this->getRows($info, $info['opcache_statistics']));
10✔
83
        $table->render();
10✔
84
    }
85

86

87
    /**
88
     * @param  array $info
89
     * @param  array $stats
90
     * @return array
91
     */
92
    protected function getRows($info, $stats)
93
    {
94
        $rows = $this->getGeneralRows($info);
10✔
95

96
        if (isset($info['interned_strings_usage'])) {
10✔
97
            $rows = array_merge($rows, $this->getStringsRows($info));
10✔
98
        }
99

100
        return array_merge($rows, $this->getOpcacheStatsRows($stats));
10✔
101
    }
102

103
    /**
104
     * @param  array $info
105
     * @return array
106
     */
107
    protected function getGeneralRows($info)
108
    {
109
        return [
10✔
110
            ['Enabled', $info['opcache_enabled'] ? 'Yes' : 'No'],
10✔
111
            ['Cache full', $info['cache_full'] ? 'Yes' : 'No'],
10✔
112
            ['Restart pending', $info['restart_pending'] ? 'Yes' : 'No'],
10✔
113
            ['Restart in progress', $info['restart_in_progress'] ? 'Yes' : 'No'],
10✔
114
            ['Memory used', Formatter::bytes($info['memory_usage']['used_memory'])],
10✔
115
            ['Memory free', Formatter::bytes($info['memory_usage']['free_memory'])],
10✔
116
            ['Memory wasted (%)', sprintf("%s (%s%%)", Formatter::bytes($info['memory_usage']['wasted_memory']), $info['memory_usage']['current_wasted_percentage'])],
10✔
117
        ];
10✔
118
    }
119

120
    /**
121
     * @param  array $info
122
     * @return array
123
     */
124
    protected function getStringsRows($info)
125
    {
126
        return [
10✔
127
            ['Strings buffer size', Formatter::bytes($info['interned_strings_usage']['buffer_size'])],
10✔
128
            ['Strings memory used', Formatter::bytes($info['interned_strings_usage']['used_memory'])],
10✔
129
            ['Strings memory free', Formatter::bytes($info['interned_strings_usage']['free_memory'])],
10✔
130
            ['Number of strings', $info['interned_strings_usage']['number_of_strings']],
10✔
131
        ];
10✔
132
    }
133

134
    /**
135
     * @param  array $stats
136
     * @return array
137
     */
138
    protected function getOpcacheStatsRows($stats)
139
    {
140
        return [
10✔
141
            new TableSeparator(),
10✔
142
            ['Cached scripts', $stats['num_cached_scripts']],
10✔
143
            ['Cached keys', $stats['num_cached_keys']],
10✔
144
            ['Max cached keys', $stats['max_cached_keys']],
10✔
145
            ['Start time', Formatter::date($stats['start_time'], 'U')],
10✔
146
            ['Last restart time', $stats['last_restart_time'] ? Formatter::date($stats['last_restart_time'], 'U') : 'Never'],
10✔
147
            ['Oom restarts', $stats['oom_restarts']],
10✔
148
            ['Hash restarts', $stats['hash_restarts']],
10✔
149
            ['Manual restarts', $stats['manual_restarts']],
10✔
150
            ['Hits', $stats['hits']],
10✔
151
            ['Misses', $stats['misses']],
10✔
152
            ['Blacklist misses (%)', sprintf('%s (%s%%)', $stats['blacklist_misses'], $stats['blacklist_miss_ratio'])],
10✔
153
            ['Opcache hit rate', $stats['opcache_hit_rate']],
10✔
154
        ];
10✔
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc