RobiNN1 / phpCacheAdmin

A web dashboard for your favorite caching system.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memcached keys (in list) not shown

codebude opened this issue · comments

What version of phpCacheAdmin are you using?

v1.5.1

Cache system and version

Memcached 1.6.20

Extension or client and version

PHP Memcached extension v3.2.0

PHP Version

7.4.33

Operating System

Linux a5873251612e 5.15.0-70-generic #77-Ubuntu (via Docker)

Describe the issue

In the Memcached view the list with keys is empty. At first I thought, it might be a similar to #15, but in opposite to this bug report, in my case the stats are showing correctly. (Key count is correct, but only the list stays empty. See screenshot.)

image

Additional info:

  • The memcached server runs as Docker container
  • The memcached server runs with -o lru_crawler flag
  • I have a second webserver container (running with PHP 8.2.5 and PHPMem v1.1.0 instead of the Memcached extension). This server points to the same Memcached instance and shows the key list correctly. Thus I assume, that the problem is not related to the Memcached server, but has to do something with either the PHP version (7.4.33) or the PHP Memcached extension.

Question:
How to debug the problem? (In the webbrowser's console nor in my webserver's logs I don't see any errors.)

That's interesting problem because under the hood for obtaining keys it always uses custom php script that runs lru_crawler metadump all.

phpCacheAdmin is also installed via Docker? If not, chanage this

if (extension_loaded('memcached')) {
$memcached = new Compatibility\Memcached($server);
} elseif (extension_loaded('memcache')) {
$memcached = new Compatibility\Memcache($server);
} elseif (class_exists(Compatibility\PHPMem::class)) {
$memcached = new Compatibility\PHPMem($server);
} else {
throw new DashboardException('Memcache(d) extension or PHPMem client is not installed.');
}

to

if (class_exists(Compatibility\PHPMem::class)) {
    $memcached = new Compatibility\PHPMem($server);
} else {
    throw new DashboardException('Memcache(d) extension or PHPMem client is not installed.');
}

It will use my PHPMem client instead of a native php extension.

Hi @RobiNN1 ,

thanks for the feedback. I did the code change, but it didn't help. It seems that it is a general problem with the list, because the OPCache list isn't working either.

I have two webservers running with images from: https://github.com/thecodingmachine/docker-images-php
One server runs the image with PHP 8.2.5, the other runs PHP 7.4.33.

In both servers I downloaded the release from your Github's release page and simply extracted the zip-file.

With the PHP 8.2.5 container everything is fine. With the PHP 7.4.33 container the tables are empty (for Memcached, as also for the OPCache dashboard). So it seems something with the PHP 7.4.33 container prevents that the tables are rendered correctly.

Ok, I think I found the bug. It's related to the use of the stripos function in the Dashboard traits:

(If there are more places where you use stripos, those places should be fixed, too.)

The problem is for cases, where $search is an empty string. (So when the Dashboard is loaded without any search for a specific key.) For PHP >= 8 stripos returns true (and thus all keys will be added to the table). But for PHP < 8 an empty needle, doesn't return a true value.

You can read about it here: https://php.watch/versions/8.0/string-function-empty-needles

So to make the code working for PHP < 8, I suggest the following fix (e.g. for Memcached dashboard).
Change

if (stripos($key, $search) !== false) {
from:

if (stripos($script['full_path'], $search) !== false) {

to

if ($search == "" || stripos($script['full_path'], $search) !== false) {

Interesting, I don't know about this change in stripos. Thanks for the fix, I'll add it later.

You were quicker. Feel free to close my PR.