• Resolved xorred

    (@xorred)


    I have memcached running on ubuntu (latest stable), service Memcached status returns a running service, sock file gets created, I can nc -U the sock file and run stats on it no problem.

    However when I try to telnet to 11211 it says connection refused. I read that is because the service is using a Unix socket.

    Then…
    Your official debug / troubleshooting page says:
    https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:cache:object_cache#how_to_debug

    Try service memcached status, to make sure the service is active (running).
    Try ss -lptun | grep 11211, to make sure the Memcached port is listening.
    Try telnet localhost 11211, to make sure you can connect to localhost successfully.

    the ss-lptun command returns nothing.
    Telnet fails.

    There are no entries in the log, too.
    In the plugin, I see “connection failed” – both when I use the socket instructions (to insert the sock file in the host field, and 0 for port) and when I use localhost and port 11211.

    I am at the end of my rope for troubleshooting this. Any suggestions? P.S. this is the default droplet provided by litespeed on digitalocean

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    are you using memcached unix socket ?

    make sure your PHP user has permission to read/write to that socket file

    Best regards,

    Plugin Support Cold Egg

    (@eric780217)

    Hi @xorred ,

    May I know if this is a cloud image launched from marketplace?

    If so, the default object cache has set to use unix socket, so check the port command may not help. Please consider to Method Redis, Host set to /var/run/redis/redis-server.sock and Port set to 0.

    Best,
    Eric

    Thread Starter xorred

    (@xorred)

    @qtwrk – can you please clarify how I could make sure of that besides the ls -lah, showing the right permissions, same as the webserver and Memcached ‘-u’ user switch? Is there a test I could run?
    @eric780217 thanks, Redis works, but I would really like to use Memcached.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    please create a php file with code

    <?php
    
    $mem = new Memcached();
    #$mem->addServer("127.0.0.1", 11211);
    $mem->addServer('/var/www/memcached.sock',0);
    //$mem->connect("127.0.0.1", 11211);
    
    $mem->set('key1', 'This is first value', 60);
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val ."<br />";
    
    $mem->replace('key1', 'This is replace value', 60);
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val . "<br />";
    
    $arr = array('aaa', 'bbb', 'ccc', 'ddd');
    $mem->set('key2', $arr, 60);
    $val2 = $mem->get('key2');
    echo "Get key2 value: ";
    print_r($val2);
    echo "<br />";
    
    $mem->delete('key1');
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val . "<br />";
    
    $mem->flush();
    $val2 = $mem->get('key2');
    echo "Get key2 value: ";
    print_r($val2);
    echo "<br />";
    
    $mem->close();

    replace /var/www/memcached.sock to your actual path if it’s different , then access this file via browser, and post what it outputs.

    Best regards,

    Thread Starter xorred

    (@xorred)

    Get key1 value:
    Get key1 value:
    Get key2 value: Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )
    Get key1 value:
    Get key2 value:

    This is the file’s output.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    it should output like this

    Get key1 value: This is first value
    Get key1 value: This is replace value
    Get key2 value: Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )
    Get key1 value:
    Get key2 value:

    what’s permission on that memcached.sock file ? and PHP user ?

    Best regards,

    Thread Starter xorred

    (@xorred)

    php user is www-data
    permissions on the sock file:
    srwxrwx— 1 www-data www-data 0 Aug 18 16:27 memcached.sock

    Thread Starter xorred

    (@xorred)

    Thought to share the memcached conf here: (ps. I *JUST* changed the port to 0, figured out 11211 was wrong. Output of the test file is still the same…

    # memcached default config file
    # 2003 - Jay Bonci <jaybonci@debian.org>
    # This configuration file is read by the start-memcached script provided as
    # part of the Debian GNU/Linux distribution.
    
    # Run memcached as a daemon. This command is implied, and is not needed for the
    # daemon to run. See the README.Debian that comes with this package for more
    # information.
    -d
    
    # Log memcached's output to /var/log/memcached
    logfile /var/log/memcached.log
    
    # Be verbose
    -v
    
    # Be even more verbose (print client commands as well)
    # -vv
    
    # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
    # Note that the daemon will grow to this size, but does not start out holding this much
    # memory
    -m 128 
    
    # Default connection port is 11211
    -p 0
    
    # Run the daemon as root. The start-memcached will default to running as root if no
    # -u command is present in this config file
    -u www-data  
    
    # Specify which IP address to listen on. The default is to listen on all IP addresses
    # This parameter is one of the only security measures that memcached has, so make sure
    # it's listening on a firewalled interface.
    -l 127.0.0.1
    # Limit the number of simultaneous incoming connections. The daemon default is 1024
    # -c 1024
    
    # Lock down all paged memory. Consult with the README and homepage before you do this
    # -k
    
    # Return error when memory is exhausted (rather than removing items)
    # -M
    
    # Maximize core file limit
    # -r
    
    # Use a pidfile
    -P /var/run/memcached/memcached.pid
    -s /var/www/memcached.sock
    -a 0766
    -p /tmp/memcached.pid
    
    Thread Starter xorred

    (@xorred)

    Also, changed your code to reflect a socket connection and now it works (seems to)

    $mem = new Memcached();
    #$mem->addServer("127.0.0.1", 0);
    $mem->addServer('/var/www/memcached.sock',0);
    //$mem->connect("/var/www/memcached.sock", 0);
    $mem->set('key1', 'This is first value', 60);
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val ."<br />";
    $mem->replace('key1', 'This is replace value', 60);
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val . "<br />";
    $arr = array('aaa', 'bbb', 'ccc', 'ddd');
    $mem->set('key2', $arr, 60);
    $val2 = $mem->get('key2');
    echo "Get key2 value: ";
    print_r($val2);
    echo "<br />";
    $mem->delete('key1');
    $val = $mem->get('key1');
    echo "Get key1 value: " . $val . "<br />";
    $mem->flush();
    $val2 = $mem->get('key2');
    echo "Get key2 value: ";
    print_r($val2);
    Plugin Support qtwrk

    (@qtwrk)

    So you got the test script working with memcached socket now ?

    Thread Starter xorred

    (@xorred)

    yep. Overall I think this thread can be closed. Thanks a LOT for your help so far!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘memcached not working’ is closed to new replies.