Memcached provides a controlled, server-based memory caching service. The server is reasonably easily configured and installed, but provides a sophisticated caching configuration. PHP support for the library is available through the PHP PEAR memcache or memcached libraries. If both are available, the memcache library will be used.
Your platform and PHP version will be the primary decision factors between using memcache or memcached. In general, the following guidelines can be used.
|Windows||5.x, 7.x||PEAR Memcache library|
|7.x||PEAR Memcached library|
It's also worth noting that compression is not supported with memcached. If you need cache compression, the memcache library is recommended.
For larger environments, distributed Memcache hosts can be specified.
$db = NewADOConnection($driver='mysqli'); /* * Enable memcache */ $db->memCache = true; /* * Add one or more servers, for use in distributed systems */ $db->memCacheHost = array('192.168.0.78', '192.168.0.79', '192.168.0.80'); /* * Optionally add the server port if it differs from the default */ $db->memCachePort = 11211; /* * Use 'true' to store the item compressed (uses zlib) * Note; Compression is only supported using the memcache library. This * parameter will be ignored when using the memcached library */ $db->memCacheCompress = false; /* * We connect to the database, not the memcache server */ $db->connect('localhost','mysql-user','mysql-password','employees');