Created
February 4, 2014 06:09
-
-
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 …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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