57

/opt/eduserver/eduserver gives me options:

Usage: /opt/eduserver/eduserver {start|stop|startphp|startwww|startooo|stopphp|stopwww|stopooo|restartphp|restartwww|restartooo|status|restart|reload|force-reload}

where memcache is php module there is memcache.ini in /opt/eduserver/etc/php/conf.d.

I want to clear the memcache from command line. Can I do it somehow without 'touching' any other part of the web server?

Radek
  • 1,133

8 Answers8

115

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.

heiko
  • 1,783
45

This will also work using netcat

echo "flush_all" | nc -q 2 localhost 11211 

Then just wait for the "OK".

Danie
  • 1,370
26

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
robbrit
  • 363
12

In Bash you may use this fancy syntax:

echo flush_all > /dev/tcp/localhost/11211

Otherwise use memflush command:

memflush --servers=localhost
kenorb
  • 7,125
4

(sleep 2; echo flush_all; sleep 2; echo quit; ) | telnet 127.0.0.1 11211

if you want to run it non-interactively

thanks to @heiko

Radek
  • 1,133
4

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.

1

Here is a function to flush memcached via PHP, in case that you need to refresh it without logging into ssh...

You can just http://yourserver.com/memflush.php

Call this file memflush.php

<?php

$socket = fsockopen("localhost", "11211", $errno, $errstr);

if($socket) { 
    echo &quot;Connected. &lt;br /&gt;&lt;br /&gt;&quot;; 
}
else { 
    echo &quot;Connection failed!&lt;br /&gt;&lt;br /&gt;&quot;; 
}

fputs($socket, &quot;flush_all\r\n&quot;); 
$buffer = &quot;&quot;; 

fclose($socket); 

?>

0

in case you use a socket for connecting to memcached the syntax is

echo "flush_all" | nc -U ~/memcached.sock

staabm
  • 101
  • 1