We are using Memcached to cache. Here is part of our local.xml:


The problem is the only way I can flush the cache is using SSH and the command:

echo "flush_all" | nc -U /var/tmp/path_to_cache.sock

This is OK but if one of the admins wants to add a category or something they can't access SSH and therefore flush the cache.

Is there a simple way that memcached can be flushed from the backend or by running a script?

This is not a duplicate of any of the other questions as I'm looking for a specific way to clear memcached.


1 Answer 1


exec or shell_exec should be able to help you in this.

So you could set up a php script like this:

shell_exec(nc -U /var/tmp/path_to_cache.sock);

As long as this can not be put into a Magento custom module you should place that script at least in a sub directory and set up some .htaccess protection.

Making a custom module giving the backend user a button where they can click on however would be much nicer for sure.

A general note about exec / shell_exec: There are reasons why you would run a shell command in the shell. Calling such scripts in a browser can lead to troubles for example when it comes to execution time restrictions. Please also note that the use of exec / shell_exec depends on your system/server setup in general and especially on the enforced security settings.

exec / shell_exec references:

  • there is no need to reinvent the wheel, magento already has it all by default.
    – MagenX
    Commented Jan 31, 2018 at 8:40

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