/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?


yes. you can clear the memcache. try:

telnet localhost 11211

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

  • 3
    Can I do this non interactively?
    – Radek
    Apr 13 '11 at 23:54
  • 2
    I'm trying to verify this actually was effective. So far stats still shows total_items 3926. I was expecting total_items to drop to 0. Is that not how to verify the cache was flushed? Jun 4 '13 at 18:01
  • 5
    @DannyArmstrong, flush only marks items as expired. Memcache doesn't remove expired items from the cache straight away for performance reasons. You can get expired items, so they have vanished from an API perspective
    – TerryE
    Jul 29 '14 at 17:52
  • 1
    @TerryE - Do you mean to say "You can't get expired items" rather than "You can get expired items"? Jan 12 '17 at 11:32
  • 1
    Yes I do. Sorry
    – TerryE
    Jan 13 '17 at 13:31

This will also work using netcat

echo "flush_all" | nc -q 2 localhost 11211 

Then just wait for the "OK".

  • 4
    w/o hardcoded 2 seconds: printf "flush_all\nquit\n" | nc -q -1 127.1 11211
    – youfu
    Apr 30 '15 at 15:50
  • 3
    OSX needs -w for timeout: echo "flush_all" | nc -w 2 localhost 11211
    – mahemoff
    Oct 14 '15 at 6:51
  • w/o quit & wait: printf "flush_all" | nc localhost 11211 Feb 20 '17 at 11: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
  • 2
    In Red Hat distributions, the utility is included in libmemcached.
    – Kevin
    May 23 '16 at 18:44

In Bash you may use this fancy syntax:

echo flush_all > /dev/tcp/localhost/11211

Otherwise use memflush command:

memflush --servers=localhost
  • As telnet and nc was not available on our servers, the first solution works fine, thanks.
    – Getz
    Mar 8 '18 at 9:31

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/

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


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

if you want to run it non-interactively

thanks to @heiko

  • This worked for me, as I had a host where I didn't want to install nc. Note that I worked fine for me without either the initial sleep` or the final quit. I did ( echo 'flush_all' ; sleep 2 ) | telnet myhost.fqdn.com 11211 Dec 9 '16 at 20:43

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

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


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


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

    if($socket) { 
        echo "Connected. <br /><br />"; 
    else { 
        echo "Connection failed!<br /><br />"; 

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.