Skip to content

Instantly share code, notes, and snippets.

@cam8001
Last active August 29, 2015 14:01
Show Gist options
  • Save cam8001/3f11c1f1f72a438f7ff1 to your computer and use it in GitHub Desktop.
Save cam8001/3f11c1f1f72a438f7ff1 to your computer and use it in GitHub Desktop.
drupal_scan_large_cache_objects.php
<?php
$user = '';
$pass = '';
$database = '';
$limit = 1000000;
$dsn = 'mysql:dbname=' . $database . ';unix_socket=/var/run/mysqld/mysqld.sock';
try {
$dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$ctables = $dbh->query("SHOW TABLES LIKE 'cache%'",PDO::FETCH_NUM);
while($result = $ctables->fetch()) {
$caches[] = $result[0];
}
foreach ($caches as $key => &$cache) {
print "Checking cache: " . $cache . PHP_EOL;
$sth = $dbh->prepare("SELECT cid, length(data) length FROM " . $cache . " WHERE LENGTH(data) > ?");
$sth->execute(array($limit));
$result = $sth->fetchAll();
foreach ($result as $record) {
print "cid: " . $record['cid'] . PHP_EOL;
print "length: " . $record['length'] . " bytes" . PHP_EOL;
}
print PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment