Skip to content

Commit 02c81f0

Browse files
committed
Add APCu support
1 parent 69ae0b3 commit 02c81f0

8 files changed

Lines changed: 527 additions & 5 deletions

File tree

.github/img/apcu.png

91.3 KB
Loading

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center"><img src=".github/img/logo-colored.svg" width="400" alt="Logo"></p>
2-
<p align="center">Web dashboard for Redis, Memcache(d) and OPCache.</p>
2+
<p align="center">A web dashboard for your favorite caching system.</p>
33

44
![Visitor Badge](https://visitor-badge.laobi.icu/badge?page_id=RobiNN1.phpCacheAdmin)
55

@@ -10,10 +10,16 @@
1010
</tr>
1111
<tr>
1212
<td><img alt="OPCache" src=".github/img/opcache.png"></td>
13-
<td><img alt="Server tab (default)" src=".github/img/server.png"></td>
13+
<td><img alt="APCu" src=".github/img/apcu.png"></td>
1414
</tr>
1515
</table>
1616

17+
<div align="center">
18+
<img width="450" alt="Server tab (default)" src=".github/img/server.png">
19+
20+
Server tab (default)
21+
</div>
22+
1723
## Installation
1824

1925
Simply extract the content. Optional but highly recommended, run `composer install` before use.
@@ -90,9 +96,11 @@ To add another server, add the same environment variables, but change 0 to 1 (2
9096
## Requirements
9197

9298
- PHP >= 7.4
93-
- redis, memcache(d) or opcache php extensions (if none of them is installed, only the Server tab will be available)
99+
- redis, memcache(d), opcache or apcu php extensions (if none of them is installed, only the Server tab will be available)
94100

95101
## Development
96102

97103
For compiling Tailwind CSS run `npm install` and then
98104
`npm run build` or `npm run watch` for auto-compiling.
105+
106+
<!-- Font used in logo Arial Rounded MT Bold -->

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "robinn/phpcacheadmin",
3-
"description": "Web dashboard for Redis, Memcache(d) and OPCache.",
3+
"description": "A web dashboard for your favorite caching system.",
44
"keywords": [
55
"redis",
66
"memcache",
77
"memcached",
88
"opcache",
9+
"apcu",
910
"cache",
1011
"admin",
1112
"dashboard",
@@ -29,7 +30,8 @@
2930
"suggest": {
3031
"ext-redis": "Required for use the redis dashboard.",
3132
"ext-memcache": "Required for the memcache dashboard.",
32-
"ext-memcached": "Required for the memcached dashboard."
33+
"ext-memcached": "Required for the memcached dashboard.",
34+
"ext-apcu": "Required for the apcu dashboard."
3335
},
3436
"require-dev": {
3537
"clue/phar-composer": "^1.4",

config.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
RobiNN\Pca\Dashboards\Redis\RedisDashboard::class,
1919
RobiNN\Pca\Dashboards\Memcached\MemcachedDashboard::class,
2020
RobiNN\Pca\Dashboards\OPCache\OPCacheDashboard::class,
21+
RobiNN\Pca\Dashboards\APCu\APCuDashboard::class,
2122
],
2223
'redis' => [
2324
[
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* This file is part of phpCacheAdmin.
4+
*
5+
* Copyright (c) Róbert Kelčák (https://kelcak.com/)
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace RobiNN\Pca\Dashboards\APCu;
14+
15+
use RobiNN\Pca\Dashboards\DashboardInterface;
16+
use RobiNN\Pca\Helpers;
17+
use RobiNN\Pca\Template;
18+
19+
class APCuDashboard implements DashboardInterface {
20+
use APCuTrait;
21+
22+
private Template $template;
23+
24+
public function __construct(Template $template) {
25+
$this->template = $template;
26+
}
27+
28+
/**
29+
* Check if an extension is installed.
30+
*
31+
* @return bool
32+
*/
33+
public function check(): bool {
34+
return extension_loaded('apcu');
35+
}
36+
37+
/**
38+
* Get dashboard info.
39+
*
40+
* @return array<string, string>
41+
*/
42+
public function getDashboardInfo(): array {
43+
return [
44+
'key' => 'apcu',
45+
'icon' => 'opcache', // it doesn't have its own logo..
46+
'title' => 'APCu',
47+
'color' => 'slate',
48+
];
49+
}
50+
51+
/**
52+
* Ajax content.
53+
*
54+
* @return string
55+
*/
56+
public function ajax(): string {
57+
$return = '';
58+
59+
if (isset($_GET['deleteall']) && apcu_clear_cache()) {
60+
$return = $this->template->render('components/alert', [
61+
'message' => 'Cache has been cleaned.',
62+
]);
63+
}
64+
65+
if (isset($_GET['delete'])) {
66+
$return = $this->deletekey();
67+
}
68+
69+
return $return;
70+
}
71+
72+
/**
73+
* Data for info panels.
74+
*
75+
* @return array<string, mixed>
76+
*/
77+
public function info(): array {
78+
$info = apcu_cache_info();
79+
80+
$memory_info = apcu_sma_info();
81+
82+
$total_memory = $memory_info['num_seg'] * $memory_info['seg_size'];
83+
$memory_used = ($memory_info['num_seg'] * $memory_info['seg_size']) - $memory_info['avail_mem'];
84+
85+
$hit_rate = (int) $info['num_hits'] !== 0 ? $info['num_hits'] / ($info['num_hits'] + $info['num_misses']) : 0;
86+
87+
return [
88+
'panels' => [
89+
[
90+
'title' => 'Status',
91+
'moreinfo' => true,
92+
'data' => [
93+
'Start time' => Helpers::formatTime($info['start_time']),
94+
'Cache full count' => $info['expunges'],
95+
],
96+
],
97+
[
98+
'title' => 'Memory',
99+
'data' => [
100+
'Total' => Helpers::formatBytes((int) $total_memory),
101+
'Used' => Helpers::formatBytes((int) $memory_used),
102+
'Free' => Helpers::formatBytes((int) $memory_info['avail_mem']),
103+
],
104+
],
105+
[
106+
'title' => 'Stats',
107+
'data' => [
108+
'Cached scripts' => $info['num_entries'],
109+
'Hits' => Helpers::formatNumber((int) $info['num_hits']),
110+
'Misses' => Helpers::formatNumber((int) $info['num_misses']),
111+
'Hit rate' => round($hit_rate * 100).'%',
112+
],
113+
],
114+
],
115+
];
116+
}
117+
118+
/**
119+
* Show info panels.
120+
*
121+
* @return string
122+
*/
123+
public function showPanels(): string {
124+
if (isset($_GET['moreinfo']) || isset($_GET['form']) || isset($_GET['view'], $_GET['key'])) {
125+
return '';
126+
}
127+
128+
return $this->template->render('partials/info', [
129+
'title' => 'APCu',
130+
'extension_version' => phpversion('apcu'),
131+
'info' => $this->info(),
132+
]);
133+
}
134+
135+
/**
136+
* Dashboard content.
137+
*
138+
* @return string
139+
*/
140+
public function dashboard(): string {
141+
$info = apcu_cache_info();
142+
143+
if (isset($_GET['moreinfo'])) {
144+
$return = $this->moreInfo($info);
145+
} elseif (isset($_GET['view']) && !empty($_GET['key'])) {
146+
$return = $this->viewKey();
147+
} elseif (isset($_GET['form'])) {
148+
$return = $this->form();
149+
} else {
150+
$return = $this->mainDashboard($info);
151+
}
152+
153+
return $return;
154+
}
155+
}

0 commit comments

Comments
 (0)