Warning: Memcache::get() [memcache.get]: Node no longer exists

懵懂的女人 提交于 2019-12-08 14:25:52

问题


I am new to memcached but I do need to fix this error quick on the website

I don't know where to cut in?

Anything that I can do to find out which node or key memcached failed to get?

Any log files can I look into?


回答1:


This occurs when you store an object which has references to recources such as file descriptors or database connections. It can also occur if the object you get is of a class which isn't loaded when you get it from memcached.

To find out which memcached key fails, you could set a custom error handler, which can access the memcached key, just before the call to Memcached::get and restore it afterwards. Then you can log the warning together with the key.

[Edit] Here's an example:

<?
class MyMemcachedWrapper {

    private $key;

    public function get($key) {

        // Save the key in an instance variable so it will be available in
        // the error handler
        $this->key = $key;

        set_error_handler(array($this, 'handleError'));
        $value = Memcached::get($key);
        restore_error_handler();

        return $value;
    }

    public function handleError($errno, $errstr) {

        // Here we have both the key and the error message from memcached
        $message = "Memcached error '$errstr' while fetching key '{this->key}'";

        // ... and we can log it to a file or db or something
        file_put_contents("memcached-errors.log", $message, FILE_APPEND);
    }
}

// Then use it like this
$memcached_wrapper = new MyMemcachedWrapper();
$value = $memcached_wrapper->get('xyz');


来源:https://stackoverflow.com/questions/6224204/warning-memcacheget-memcache-get-node-no-longer-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!