Memcached is a high-performance distributed memory object cache system for dynamic Web applications to reduce database loads. it caches data and objects in the memory to reduce the number of times the database is read, this improves the speed of dynamic and database-driven websites. 1. add extension... memcached is a high-performance distributed memory object cache system for dynamic Web applications to reduce database loads. it caches data and objects in the memory to reduce the number of times the database is read, this improves the speed of dynamic and database-driven websites.
1. add extension package
Php_memcache.dll
2. add the following code in PHP. INI:
Extension = php_memcache.dll
3. the program code is as follows:
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/* cl Ass 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"
"; If ($ mem-> set ('key1', $ con, MEMCACHE_COMPRESSED, 60) {echo 'add resource OK ';} * // query $ val = $ mem-> get ('key1'); // modify // replace if ($ mem-> replace ("key11 ", 'Hello', MEMCACHE_COMPRESSED, 60) {echo 'replace OK ';} else {echo 'replace no OK';} // delete echo"
"; If ($ mem-> delete ('key14') {echo 'key14 delete';} else {echo 'key14 nonexistent ';}
This article focuses on basic applications. if you need more in-depth study, we will provide relevant tutorials in the future. you can also go to the manual to learn.
Tutorial address:
Reprinted! But please include the article address ^