Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Last active July 11, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szepeviktor/8a818f4b4c4e680fc2d90e6c2653814d to your computer and use it in GitHub Desktop.
Save szepeviktor/8a818f4b4c4e680fc2d90e6c2653814d to your computer and use it in GitHub Desktop.
PhpFastCache object analyzer with Redis Driver
<?php
// https://github.com/PHPSocialNetwork/phpfastcache/blob/master/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php#L49-L64
const DATA_WRAPPER_INDEX = 'd';
// https://github.com/phpredis/phpredis#get
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
$classList = [];
$it = NULL;
while ($arr_keys = $redis->scan($it)) {
foreach ($arr_keys as $key) {
if ($redis->type($key) !== Redis::REDIS_STRING) {
continue;
}
$value = unserialize($redis->get($key));
if (!is_array($value) || !array_key_exists(DATA_WRAPPER_INDEX, $value)) {
continue;
}
if (!is_object($value[DATA_WRAPPER_INDEX]) || get_class($value[DATA_WRAPPER_INDEX]) !== '__PHP_Incomplete_Class') {
continue;
}
$className = ((array)$value[DATA_WRAPPER_INDEX])['__PHP_Incomplete_Class_Name'];
$classList[$className] = ($classList[$className] ?? 0) + 1;
}
// Show progress
echo '.';
}
asort($classList);
var_dump($classList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment