$memcache->set() failing, why?

View: New views
1 Messages — Rating Filter:   Alert me  

$memcache->set() failing, why?

by langdon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How can I determine why a call to set would fail?  Are there any memcached logs or can I somehow peer into the process and read exceptions?

Oddly enough, I have some code here that fails to set *only* on certain keys...

For example, my script is as follows:

test_memcache('lb_top_selling_camera');
test_memcache('lb_top_selling_camera');
test_memcache('lb_top_selling_Printer');
test_memcache('lb_top_selling_camera');
test_memcache('lb_top_selling_camera');

And my output:

get lb_top_selling_camera
get lb_top_selling_camera
get lb_top_selling_printer
 - set lb_top_selling_printer
 - !!broken!!
get lb_top_selling_camera
get lb_top_selling_camera

The function (sloppy atm):

function test_memcache($memcache_key)
{
        $g_memcache = memcache_init();

        debug("get $memcache_key");

        $html = $g_memcache->get($memcache_key);

        if ($html === false)
        {
                $handle = @fopen('http://www.google.com', 'r');

                if ($handle)
                {
                        $html = '';

                        while (!feof($handle))
                        {
                                $html += fgets($handle);
                        }

                        debug(" - set $memcache_key");
                       
                        $a = $g_memcache->set($memcache_key, $html, 0, 86400) or $error = true;

                        if ($error === true && is_admin())
                        {
                                //if ($a === false)print'false';
                                //debug(gettype($a));
                                debug(' - !!broken!!');
                        }

                        fclose($handle);
                }
                else
                {
                        $html = array('Data not currently available.');
                }
        }
}

function memcache_init()
{
        if (!class_exists('Memcache'))
        {
                nonfatal_error_alert('Memcache appears to be down!', false);
                return false;
        }

        try
        {
                {
                        $memcache = new Memcache;
                        $memcache->connect('localhost', 11211) or trigger_error('Memcache::Connect failed @ localhost:11211', FATAL);

                        return $memcache;
                }
        }
        catch (Exception $e)
        {
                nonfatal_error_alert('Memcache appears to be down!', false);
                return false;
        }
}

function debug()
{
        foreach(func_get_args() as $arg)
        {
                print '<xmp>';
                if (is_array($arg) | is_object($arg)) print_r($arg); else print $arg;
                print '</xmp>';
        }
}

Strangely enough, when I set $g_memcache outside of the function and use global $g_memcache, the call for "lb_top_selling_Printer" actually breaks the connection, and the subsequent camera calls fail as well.

Edit: I'm running PHP Version 5.2.0-8+etch11, memcached 1.1.12, and Debian 4.0r4.