0

This question already has an answer here:

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

<cache>
      <backend><![CDATA[memcached]]></backend>
      <memcached>
        <servers>
          <server>
            <host><![CDATA[unix:///var/tmp/path_to_cache.sock]]></host>
            <port><![CDATA[0]]></port>
            <persistent><![CDATA[1]]></persistent>
            <weight><![CDATA[2]]></weight>
            <timeout><![CDATA[5]]></timeout>
          </server>
        </servers>
        <compression><![CDATA[0]]></compression>
        <hashed_directory_level><![CDATA[]]></hashed_directory_level>
        <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
        <file_name_prefix><![CDATA[]]></file_name_prefix>
      </memcached>
    </cache>
    <session_save_path><![CDATA[unix:///var/tmp/path_to_sessions.sock?persistent=1&weight=2&timeout=10&retry_interval=10]]></session_save_path>
    <session_cache_limiter><![CDATA[]]></session_cache_limiter>

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.

marked as duplicate by Manoj Deswal, Keyur Shah, Jai, Manashvi Birla, Piyush Jan 31 '18 at 9:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

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

So you could set up a php script like this:

<?php
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 Jan 31 '18 at 8:40

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