Saturday, September 10, 2011

Empty All Memcache Data in PHP

Do you want to delete all data or empty all data that is store in memcache? How to delete all memcache data in server using PHP? How to empty all memcache data in server by PHP?

I have my own function. I hope this is work for you. While, I'm typing this, I did not directly testing it. So, If you found the bug. Report it by commenting below.

function get_memcache_keys($host = '127.0.0.1', $port = 11211) {

    $memcache = new Memcache;
    $memcache->connect($host, $port) or die ("Could not connect to memcache server");

    $list = array();
    $allSlabs = $memcache->getExtendedStats('slabs');
    $items = $memcache->getExtendedStats('items');
    foreach($allSlabs as $server => $slabs) {
        foreach($slabs AS $slabId => $slabMeta) {
           $cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
            foreach($cdump AS $keys => $arrVal) {
                if (!is_array($arrVal)) continue;
                foreach($arrVal AS $k => $v) {                   
                    $return[] = $k;
                }
           }
        }
    } 
   if(is_array($return))
   {
      return $return;
   }
   else
   {
      return '';
   }
}

function empty_memcache_data($host = '127.0.0.1', $port = 11211)
{
     
     $memcache = new Memcache;
     $memcache->connect($host, $port) or die ("Could not connect to memcache server");
     $keys = get_memcache_key($host, $port);
     if(is_array($keys))
     {
          foreach($keys as $k)
          {
              $memcache->delete($k);
          }
     }
}
empty_memcache_data();

Next, I will write down how to empty memcache data / delete all memcache data by specific namespace. See you ;)

PS: Sorry for my english and bad grammar. Actually, I am not native English speaker. If you have an errata, please free to correct it.

Wednesday, July 20, 2011

Installing MongoDB on WampServer

Installing mongodb on Wampserver is more difficult than on LAMP. But, I will give a tutorial about it, as easy as possible. Please follow these steps :