Last active
August 29, 2015 14:01
-
-
Save cam8001/3f11c1f1f72a438f7ff1 to your computer and use it in GitHub Desktop.
drupal_scan_large_cache_objects.php
This file contains hidden or 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