Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 1.93 KB

README.md

File metadata and controls

85 lines (60 loc) · 1.93 KB

Installing Memcached Server and access it with PHP

Thinking of implementing caching for your php application , Just in 6 simple (copy and paste) steps you can install and access Memcached Server.

  1. Install libevent ,libmemcached and libmemcached devel (dependency)

    yum install libevent
    yum install libmemcached libmemcached-devel
  2. Install Memcached Server

    yum install memcached
  3. Start Memcached server

    memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody

(d = daemon, m = memory, u = user, l = IP to listen to, p = port)

  1. Check your memcached server is running successfully

    ps -eaf | grep memcached
  2. Connect Memcached server via telnet

    telnet 127.0.0.1 11211
    stats
    quit
  3. Install PHP client to access Memcached Server

    pecl install memcache
  4. Restart your apache server

    service httpd restart

Usage

Downlaod cache.class.php and include it to your project
You can specify a script directly inside the cache configuration.

require_once('cache.class.php');

$cache = new MicroCache('cache key');

if($cache->check())
  die($cache->out());
else
  $cache->start();

// your code here

$cache->end();

Parameters

  • cache_on - Enable/disable caching
  • lifetime - The lifetime of the cache
  • c_type - Cache type (memcache or file)
  • patch - Path of cache directory (if memcached and/or memcache not available)

Features

  • If memcached and/or memcache is not available(error when connecting or something else), script change cache mode to 'filecache'. This provides stable cache system.
  • Script using buffering output(ob_start(), ob_get_contents(), etc...).
  • Some parameters only work if they are assigned before function check().
  • Clear current or some cache by function clear().

Contributing

Anyone and everyone is welcome to contribute.