Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@typhonius
Created February 4, 2014 06:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save typhonius/8798894 to your computer and use it in GitHub Desktop.
Save typhonius/8798894 to your computer and use it in GitHub Desktop.
Memcache by default will not accept objects larger than 1M. This script looks through all the Drupal cache tables (provided they're named correctly) and discovers any objects that would blow this requirement. Table names cannot be prepared as these are not variables that cannot be altered at runtime without changing the meaning of the query. It …
<?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