how to restart/clear memcache without restarting the whole web server?

Solution 1:

yes. you can clear the memcache. try:

telnet localhost 11211
flush_all
quit

if the memcache does not run on localhost 11211, you will have to adjust it.

Solution 2:

This will also work using netcat

echo "flush_all" | nc -q 2 localhost 11211 

Then just wait for the "OK".


Solution 3:

memcflush in the memcache tools is what you want:

memcflush --servers=localhost:11211

Change localhost to whatever your server is.

The memcache tools may not be installed on the server, if you're running a Debian-based OS you can install it like this:

sudo apt-get install libmemcached-tools

Solution 4:

In Bash you may use this fancy syntax:

echo flush_all > /dev/tcp/localhost/11211

Otherwise use memflush command:

memflush --servers=localhost

Solution 5:

Rather than waiting for timeouts you can make the command instantaneous by following flush_all with the quit command:

printf "flush_all\r\nquit\r\n" | nc localhost 11211

Alternatively if you don't have nc:

printf "flush_all\r\nquit\r\n" > /dev/tcp/127.0.0.1/11211

Though this method won't produce an output, although you can verify it works by checking stats to see that cmd_flush increased.

Tags:

Php

Memcached