All Products
Document Center

Troubleshooting for PHP connection errors with ApsaraDB for Memcache

Last Updated: Dec 20, 2017

You can troubleshoot PHP connection errors with ApsaraDB for Memcache by following these steps.

  1. Ping the IP address of ApsaraDB for Memcache to check if the address can be correctly resolved.

  2. Telnet ApsaraDB for Memcache port 11211 to check if it is accessible.

  3. Copy the following code, insert it into the system and run it.

    1. $connect = new Memcached; //Declare a new memcached connection.
    2. $connect->setOption(Memcached::OPT_COMPRESSION, false); //Turn off the compression function.
    3. $connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true); //Use the binary protocol.
    4. $connect->addServer('', 11211); //Add the address and port number of an ApsaraDB for Memcache instance.
    5. $connect->setSaslAuthData('aaaaaaaaaa, 'password'); //Set the ApsaraDB for Memcache account and password for authentication. If the password-free function has been enabled, this step can be skipped.
    6. $connect->set("hello", "world");
    7. echo 'hello: ',$connect->get("hello");
    8. $connect->quit();
    9. ?>

For example, if hello world is output, it means the ApsaraDB for Memcache connection is normal. See the following figure.