\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{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.

<pre><code class="language-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\textbackslash\{\}n";
		if (\$memcache->get(\$key) === false) \{
			\#echo "\$key not found in memcache\textbackslash\{\}n";
			\$removed++;
			unlink(\$dir . "/" . \$filename);
		\}
	\}
\}

closedir(\$dh);

\$memcache->close();

echo "\$total lock files\textbackslash\{\}n";
echo "\$removed lock files removed\textbackslash\{\}n";
</code></pre>
\end{document}
