@@ -34,13 +34,19 @@ private function serverInfo(array $servers): array {
3434 $ memcached = $ this ->connect ($ servers [Http::get ('panel ' , 'int ' )]);
3535 $ server_info = $ memcached ->getServerStats ();
3636
37+ try {
38+ $ keys = Format::number (count ($ memcached ->getKeys ()));
39+ } catch (MemcachedException $ e ) {
40+ $ keys = 'An error occurred while retrieving keys. ' ;
41+ }
42+
3743 return [
3844 'Version ' => $ server_info ['version ' ],
3945 'Open connections ' => $ server_info ['curr_connections ' ],
4046 'Uptime ' => Format::seconds ((int ) $ server_info ['uptime ' ]),
4147 'Cache limit ' => Format::bytes ((int ) $ server_info ['limit_maxbytes ' ]),
4248 'Used ' => Format::bytes ((int ) $ server_info ['bytes ' ]),
43- 'Keys ' => Format:: number ( count ( $ memcached -> getKeys ())) ,
49+ 'Keys ' => $ keys ,
4450 ];
4551 } catch (DashboardException |MemcachedException $ e ) {
4652 return [
@@ -52,9 +58,10 @@ private function serverInfo(array $servers): array {
5258 /**
5359 * Delete all keys.
5460 *
55- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
61+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
5662 *
5763 * @return string
64+ * @throws MemcachedException
5865 */
5966 private function deleteAllKeys ($ memcached ): string {
6067 if ($ memcached ->flush ()) {
@@ -69,7 +76,7 @@ private function deleteAllKeys($memcached): string {
6976 /**
7077 * Delete key or selected keys.
7178 *
72- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
79+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
7380 *
7481 * @return string
7582 * @throws MemcachedException
@@ -115,15 +122,15 @@ private function moreInfo(array $servers): string {
115122 'panel_title ' => $ server_data ['name ' ] ?? $ server_data ['host ' ].': ' .$ server_data ['port ' ],
116123 'array ' => Helpers::convertBoolToString ($ info ),
117124 ]);
118- } catch (DashboardException $ e ) {
125+ } catch (DashboardException | MemcachedException $ e ) {
119126 return $ e ->getMessage ();
120127 }
121128 }
122129
123130 /**
124131 * Get all keys with data.
125132 *
126- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
133+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
127134 *
128135 * @return array<int, array<string, string|int>>
129136 * @throws MemcachedException
@@ -135,7 +142,7 @@ private function getAllKeys($memcached): array {
135142 $ keys [] = [
136143 'key ' => $ key_data ['key ' ],
137144 'ttl ' => $ key_data ['exp ' ],
138- 'type ' => 'string ' , // In Memcache(d) everything is stored as a string.
145+ 'type ' => 'string ' , // In Memcached everything is stored as a string. Calling gettype() will slow down page loading .
139146 ];
140147 }
141148
@@ -145,7 +152,7 @@ private function getAllKeys($memcached): array {
145152 /**
146153 * Main dashboard content.
147154 *
148- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
155+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
149156 *
150157 * @return string
151158 * @throws MemcachedException
@@ -171,7 +178,7 @@ private function mainDashboard($memcached): string {
171178 /**
172179 * View key value.
173180 *
174- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
181+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
175182 *
176183 * @return string
177184 * @throws MemcachedException
@@ -205,7 +212,7 @@ private function viewKey($memcached): string {
205212 return $ this ->template ->render ('partials/view_key ' , [
206213 'key ' => $ key ,
207214 'value ' => $ value ,
208- 'type ' => ' string ' , // In Memcache(d) everything is stored as a string.
215+ 'type ' => null ,
209216 'ttl ' => Format::seconds ($ ttl ),
210217 'size ' => Format::bytes (strlen ($ value )),
211218 'encode_fn ' => $ encode_fn ,
@@ -219,7 +226,7 @@ private function viewKey($memcached): string {
219226 /**
220227 * Import key.
221228 *
222- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
229+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
223230 *
224231 * @return void
225232 * @throws MemcachedException
@@ -241,7 +248,7 @@ private function import($memcached): void {
241248 /**
242249 * Add/edit form.
243250 *
244- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
251+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
245252 *
246253 * @return string
247254 * @throws MemcachedException
@@ -276,9 +283,10 @@ private function form($memcached): string {
276283 /**
277284 * Save key.
278285 *
279- * @param Compatibility\Memcache |Compatibility\Memcached |Compatibility\PHPMem $memcached
286+ * @param Compatibility\Memcached |Compatibility\Memcache |Compatibility\PHPMem $memcached
280287 *
281288 * @return void
289+ * @throws MemcachedException
282290 */
283291 private function saveKey ($ memcached ): void {
284292 $ key = Http::post ('key ' );
0 commit comments