====== Memcached Setup ====== ===== Description ===== This section describes connecting to an already configured Memcache server with either the [[v6:caching:memcached]] or [[v6:caching:memcache]] connection plugins. Information about installation and configuration of Memcached servers can be found [[https://memcached.org/|here]]. ===== The Memcache Library ===== There are 2 distinct PEAR modules for connecting to a [[wp>Memcached]] server: the [[https://pecl.php.net/package/memcache|Memcache]] library and the [[https://pecl.php.net/package/memcached|Memcached]] library. * Windows support is only available for the //Memcache// library. * //Memcache// should be used in PHP 5.x environments on UNIX platforms. * //Memcached// should be used in PHP 7.x environments on UNIX platforms. * If both libraries are available, //Memcache// will be used. ===== Why can't I use the memcached library under Windows? ===== The memcached library is much more heavily featured, more modern and better maintained. The problem with it is not a problem with ADOdb, nor a problem with PHP. The PHP module is dependent on the 3rd party library **libmemcache**, which has no Windows support. Any Windows DLLs you might find floating around the web will __always__ be built on the memcache library. ===== Usage ===== /* * Example for logging */ $debugStreamHandler = new StreamHandler('/logs/debug.log', Logger::DEBUG); $criticalStreamHandler = new StreamHandler('/logs/critical.log', Logger::CRITICAL); $streamHandlers = array( Logger::DEBUG=>$debugStreamHandler, Logger::CRITICAL=>$criticalStreamHandler); $dbParameters = array( 'host'=>'192.168.86.85', 'user'=>'adodb', 'password'=>'adodb', 'database'=>'employees'); /* * Enable memcache */ $memcacheClass = new \ADOdb\cache\plugins\memcached\ADOCachingDefinitions; $memcacheClass->memCacheControllers = array( array('host'=>'192.168.86.91','port'=>'11211','weight'=>70), array('host'=>'192.168.86.92','port'=>'11211','weight'=>30)); $memcacheClass->memCacheOptions = array( Memcached::OPT_HASH=>Memcached::HASH_MURMUR ); $acd = new ADOdb\ADOConnectionDefinitions( $streamHandlers, null, $memcacheClass); $acd->driver = 'mysqli'; $acd->dbParameters = $dbParameters; $obj = new ADOdb\connector($acd); $db = $obj->connect(); /* * look for a cached query with a life of 2400 seconds, in the mygroup group */ $options = array('cache'=>array( 'cachesecs'=>2400, 'serverkey'=>'mygroup'); $sql = 'SELECT code,description FROM xref_table'; $db->execute($sql,null,$options); ===== Using Debug Mode ===== The size of query results that can be cached by the memcached server is limited by server configuration. The default is quite small. If the query is too large, and [[v6:userguide:debug|debugging]] is enabled, then an error is displayed. ADOdb.DEBUG: MEMCACHED: Loaded the MemCached Libary [] [] ADOdb.DEBUG: MEMCACHED: Successfully set memcache option 2 to 8 [] [] ADOdb.DEBUG: MEMCACHED: 71a071eb865c1bafbcc49e274a7ac6b6 cache failure: Timeout 1 (this is a notice and not an error [] [] ADOdb.DEBUG: MEMCACHED: Successfully wrote query contents on key 71a071eb865c1bafbcc49e274a7ac6b6 to memcache server [] [] ADOdb.DEBUG: MEMCACHED: Item with key 71a071eb865c1bafbcc49e274a7ac6b6 retrieved from the memcache server. [using server key server-test] [] [] ADOdb currently has no mechanism for splitting large queries into smaller chunks. {{tag>memcached cache}}