skip to Main Content

PHP version: 7.2.6

I have a memcached server running on 127.0.0.1:11211, but not 127.0.0.22:11212.

$memcached = new Memcached;
if( !$memcached->addServer('127.0.0.22', 11212) )
    die( 'memcached server error' );
else
    echo 'OK';

The actual output is "OK", why is it not ‘memcached server error’? How to determine whether the memcached server is connected?

Expected result:

memcached server error

Actual result:

OK

2

Answers


  1. The memcache client will not make a connection to a server unless you’re reading/writing to it. addServer returning true just means that the server is added to the pool, but it doesn’t imply that a connection can be made.

    Login or Signup to reply.
  2. You can test

    if ($memcached->getCacheInfo()===null) {
    // Memcached Init failed
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search