Invalid Memcache->connection member variable errors
Asked Answered
A

5

11

We are currently using Nginx as our server and memcached for caching mechanism. I was inspecting PHP error logs and lots of PHP Warnings about memcached caught my attention.

PHP Warning: Memcache::get(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180

At the line it was pointing, there is this piece of code:

$tmp = $this->_memcache->get($id);

I also see many other PHP warnings with the same warning message but different with different function calls of memcache object:

PHP Warning: Memcache::add(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180
PHP Warning: Memcache::set(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 230
PHP Warning: Memcache::delete(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 323

I did a search through the web but could not find anything that really helped. From time to time, we have some problems with our memcached. Is it possible that this some kind of issue that happens when servers are down because of some problem? I really do not have any idea about what causes these warnings. How can I correct it or at least how can I avoid these warnings?

Antarctica answered 8/1, 2013 at 14:37 Comment(2)
have you found the solution? if you don't mind...Driscoll
Do you created Connection, before trying get something from daemon?Bertberta
E
0

I found 3 references that might help you

  1. Limit of file system and memcache
  2. Possible memory leaks
  3. Memcache vs Memcached
Expectoration answered 1/3, 2013 at 11:48 Comment(0)
T
0

You need to check key max 250 chars and value max : 1MB

Thereinto answered 4/9, 2013 at 17:38 Comment(0)
K
0

Have you compiled your own php recently? It's possible ther versions are out of sync.

Knowall answered 10/11, 2013 at 1:52 Comment(1)
This isn't really an answer to their question.Drawer
L
0

I had the same problem. when i called memcache object in __destruct to update the state of my object i goot the error. and here is my solution.: call object in your class function where you change the state and be sure to send an instance of memcache to this class.

Landin answered 1/3, 2014 at 4:47 Comment(0)
V
0

While from the warning message itself, it may not be obvious, but the error may be happening when you're trying to serialize/deserialize memcache connection object itself.

For example:

class a {
  private Memcache $mc;
  private $name = 'glen';

  public function __construct(Memcache $mc) {
    $this->mc = $mc;
  }
}

$a = new a($mc);
$mc->set('a', $a);

You very likely (as me) ended up here because class having mixed concerns (the object being a model and has as other business logic as well). you can omit the unwanted mc key from serializing using __debugInfo function:

public function __debugInfo() {
    return [];
}

While writing this note, I'm not able to reproduce with my own example, so there's something else involved, perhaps memory corruption. But removing $mc property solve the problem for me.

Villar answered 8/3, 2022 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.