<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Developer Day &#187; memcache</title>
	<atom:link href="http://www.thedeveloperday.com/tag/memcache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thedeveloperday.com</link>
	<description>Staying Curious</description>
	<lastBuildDate>Fri, 03 Feb 2012 12:03:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dumping Memcache Keys</title>
		<link>http://www.thedeveloperday.com/dumping-memcache-keys/</link>
		<comments>http://www.thedeveloperday.com/dumping-memcache-keys/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 21:25:16 +0000</pubDate>
		<dc:creator>Žilvinas Šaltys</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[memcache]]></category>

		<guid isPermaLink="false">http://www.thedeveloperday.com/?p=746</guid>
		<description><![CDATA[Sometimes it&#8217;s useful to be able to quickly peek what keys memcache is storing and how old are they. A good use case for example could be to check whether something is cached or not or that they expire as they should. At first I found a way to dump memcache keys through telnet. However [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s useful to be able to quickly peek what keys memcache is storing and how old are they. A good use case for example could be to check whether something is cached or not or that they expire as they should.</p>
<p>At first I found a way to <a href="http://www.darkcoding.net/software/memcached-list-all-keys/" title="memcache keys telnet" target="_blank">dump memcache keys through telnet</a>. However if a memcache instance is fairly large and has a lot of slabs and thousands of keys it becomes impractical to do it manually.</p>
<p>I wrote a simple utility that helps me find keys across all memcache slabs.</p>
<pre name="code" class="php:nogutter">
#!/usr/bin/php
< ?php
$host = "127.0.0.1";
$port = 11211;
$lookupKey = "";
$limit = 10000;

$time = time();

foreach ($argv as $key => $arg) {
    switch ($arg) {
        case '-h':
            $host = $argv[$key + 1];
            break;
        case '-p':
            $port = $argv[$key + 1];
            break;
        case '-s':
            $lookupKey = $argv[$key + 1];
            break;
        case '-l':
            $limit = $argv[$key + 1];
    }
}

$memcache = memcache_connect($host, $port);

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');

foreach ($allSlabs as $server => $slabs) {
    foreach ($slabs as $slabId => $slabMeta) {
        if (!is_numeric($slabId)) {
            continue;
        }

        $cdump = $memcache->getExtendedStats('cachedump', (int)$slabId, $limit);

        foreach ($cdump as $server => $entries) {
            if (!$entries) {
                continue;
            }

            foreach($entries as $eName => $eData) {
                $list[$eName] = array(
                    'key' => $eName,
                    'slabId' => $slabId,
                    'size' => $eData[0],
                    'age' => $eData[1]
                );
            }
        }
    }
}

ksort($list);

if (!empty($lookupKey)) {
     echo "Searching for keys that contain: '{$lookupKey}'\n";
     foreach ($list as $row) {
        if (strpos($row['key'], $lookupKey) !== FALSE) {
            echo "Key: {$row['key']}, size: {$row['size']}b, age: ", ($time - $row['age']), "s, slab id: {$row['slabId']}\n";
        }
     }
} else {
    echo "Printing out all keys\n";
    foreach ($list as $row) {
        echo "Key: {$row['key']}, size: {$row['size']}b, age: ", ($time - $row['age']), "s, slab id: {$row['slabId']}\n";
    }
}
</pre>
<p>This script accepts 4 parameters:</p>
<blockquote style="background: #444; color: #fff; padding-left: 2px;"><p>
-h host<br />
-p port<br />
-s partial search string<br />
-l a limit of how many keys to dump from a single slab (default 10,000)
</p></blockquote>
<p>The easiest way to use it:</p>
<blockquote style="background: #444; color: #fff; padding-left: 2px;"><p>
./membrowser.php -s uk<br />
Searching for keys that contain: &#8216;uk&#8217;<br />
Key: 1_uk_xml, size: 3178b, age: 1728s, slab id: 17<br />
Key: 2_uk_xml, size: 3178b, age: 1725s, slab id: 17<br />
Key: 3_uk_xml, size: 3178b, age: 1721s, slab id: 17
</p></blockquote>
<p>Download <a href="http://www.thedeveloperday.com/uploads/membrowser.phps">memcache keys dump script</a>.</p>
<p>P.S some of the code I&#8217;ve copied from <a href="http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html" target="_blank">100days.de blog post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thedeveloperday.com/dumping-memcache-keys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP session cluster with memcache</title>
		<link>http://www.thedeveloperday.com/php-session-cluster-with-memcache/</link>
		<comments>http://www.thedeveloperday.com/php-session-cluster-with-memcache/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 17:12:52 +0000</pubDate>
		<dc:creator>Žilvinas Šaltys</dc:creator>
				<category><![CDATA[Lazyweb]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.thedeveloperday.com/php-session-cluster-with-memcache/</guid>
		<description><![CDATA[Reading planet-php.org I found this great post about how to solve PHP session clustering in an easy way. Though it&#8217;s no silver bullet but it&#8217;s definitely worth knowing about. It uses few insantances of memcache that stores the same copies of sessions. And if one instance gets down the other keeps serving the sessions. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Reading planet-php.org I found this great post about how to solve <a href="http://phpslacker.com/2009/03/02/php-session-clustering-with-memcache/" title="php session clustering">PHP session clusterin</a>g in an easy way. Though it&#8217;s no silver bullet but it&#8217;s definitely worth knowing about. It uses few insantances of memcache that stores the same copies of sessions. And if one instance gets down the other keeps serving the sessions. It&#8217;s nice to have such kind of failover. Ofcourse after recovery you have to sync the instances. And your performance is going to suffer more and more if you add more memcache instances.</p>
<p>Though myself I feel this is a great poor man&#8217;s solution <img src='http://www.thedeveloperday.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Might end up using it myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thedeveloperday.com/php-session-cluster-with-memcache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

