PHP uses memcached and php uses memcached
1. Add extension package
Php_memcache.dll
2. Add in PHP. INI
Extension = php_memcache.dll
3. Program
<? Php // create a mem object instance $ mem = new Memcache; if (! $ Mem-> connect ("10.18.110.213", 11211) {die ('Connection failed! ');} // Add // 1. add a string/* if ($ mem-> set ('key1', "beijing", MEMCACHE_COMPRESSED, 60) {echo 'add OK ';} * // 2. add Value/* if ($ mem-> set ('key1', 100, MEMCACHE_COMPRESSED, 60) {echo 'add OK ';} * // 3. add an array // Add an array as needed. if you want the serial number to be placed in, // serialize <=> unserialize, you can also use json_encode <=> json_decode $ arr = array ("bj", 'tj ') as needed '); if ($ mem-> set ('key1', $ arr, MEMCACHE_COMPRESSED, time () + 31*3600*24) {echo 'add array ok99111 ';} // 4. add object/* class Dog {public $ name; public $ age; public function _ construct ($ name, $ age) {$ this-> name = $ name; $ this-> age = $ age ;}}$ dog1 = new Dog ('puppy ', 50); if ($ mem-> set ('key1', $ dog1, MEMCACHE_COMPRESSED, 60) {echo 'add object OK ';} * // 5. add a null Boolean value/* if ($ mem-> set ('key1', false, MEMCACHE_COMPRESSED, 60) {echo 'add Boolean OK ';} * // 6. put the resource type in. /* $ con = mysql_connect ("127.0.0.1", "root", "root"); if (! $ Con) {die ('database connection failed');} var_dump ($ con); echo "<br/>"; if ($ mem-> set ('key1 ', $ con, MEMCACHE_COMPRESSED, 60) {echo 'add resource OK ';} * // query $ val = $ mem-> get ('key1 '); // modify // you can use replace if ($ mem-> replace ("key11", 'Hello', MEMCACHE_COMPRESSED, 60) {echo 'replace OK ';} else {echo 'replace no OK ';} // delete echo "<br/>"; if ($ mem-> delete ('key14 ')) {echo 'key14 delete';} else {echo 'key14 does not exist ';}