[cvs] [Wiki] created: MemcacheLockCleanup
Chuck Hagenbuch
chuck at horde.org
Thu Feb 28 02:14:55 UTC 2008
chuck Wed, 27 Feb 2008 21:14:55 -0500
Created page: http://wiki.horde.org/MemcacheLockCleanup
+ Memcache Lock Cleanup
With Horde versions before 3.2, the memcache support will generate lock
files in your temp directory. This script will clean them out - you can run
it from cron nightly. Contributed by Andrew Morgan.
<code type="php">
<?php
# Clean up stale lock files by checking if the session
# still exists in memcache
# Connect to memcache
$memcache = new Memcache;
$memcache->connect('your.memcache.server', 11211);
# Walk through lock files
$dir = "/tmp";
$total = 0;
$removed = 0;
$dh = opendir($dir) or die("Unable to open '$dir'");
while(($filename = readdir($dh)) !== false) {
if (preg_match('/^lock_([a-z0-9]+)$/', $filename, $matches)) {
$key = $matches[1];
$total++;
#echo "checking key: $key\n";
if ($memcache->get($key) === false) {
#echo "$key not found in memcache\n";
$removed++;
unlink($dir . "/" . $filename);
}
}
}
closedir($dh);
$memcache->close();
echo "$total lock files\n";
echo "$removed lock files removed\n";
</code>
More information about the cvs
mailing list