This article simply to the Code farmers introduce memcached. Memcached is an efficient and fast distributed memory object caching system that is primarily used to accelerate web dynamic applications. Today, I and yard farmers to briefly discuss the use of memcached.
1. Add memcached expansion pack
php_memcache.dll
2. Add memcached extension to php.ini
extension=php_memcache.dll
3. Procedures
Php//creating an instance of a Mem object$mem=NewMemcache; if(!$mem->connect ("10.18.110.213", 11211)){ die(' Connection failed! ')); } //add a//1. Add a String/*if ($mem->set (' Key1 ', "Beijing", memcache_compressed,60)) {echo ' Add OK '; }*///2. Add a value/*if ($mem->set (' Key1 ', 100,memcache_compressed,60)) {echo ' Add OK '; }*///3. Add an array//In the Add array is, as needed. Hope the serial number is put in,//serialize<=>unserialize, if necessary, can also json_encode <=> json_decode$arr=Array("BJ", ' TJ '); if($mem->set (' Key1 ',$arr, memcache_compressed, Time() +31*3600*24)){ Echo' Add array ok99111 '; } //4. Adding Objects/*class dog{public $name; Public $age; Public function __construct ($name, $age) {$this->name= $name; $this->age= $age; }} $dog 1=new dog (' Puppy ', 50); if ($mem->set (' Key1 ', $dog 1,memcache_compressed,60)) {echo ' Add object OK '; }*///5. Adding a null Boolean value/*if ($mem->set (' Key1 ', false,memcache_compressed,60)) {echo ' adds Boolean ok '; }*///6. Type the resource into./*$con =mysql_connect ("127.0.0.1", "root", "root"); if (! $con) {die (' failed to connect to database '); } var_dump ($con); echo "
"; if ($mem->set (' Key1 ', $con, memcache_compressed,60)) {echo ' Add resource ok '; }*///Enquiry$val=$mem->get (' Key1 ');//Modify//can use replaceif($mem->replace ("Key11", ' Hello ', memcache_compressed,60)){ Echo' Replace OK '; }Else{ Echo' Replace no OK '; } //DeleteEcho"
"; if($mem->delete (' Key14 ')){ Echo' Key14 Delete '; }Else{ Echo' KEY14 does not exist '; }
Original address: http://www.manongjc.com/article/683.html
Related reading:
PHP Extension Module memcached long connection usage analysis
PHP Module memcached Usage Guide
PHP5.5 How to use the Memcached service side in Windows installation
Introduction to how PHP memcached are used
The above describes the PHP use memcached simple sample sharing, including the memcached aspects of the content, I hope the PHP tutorial interested in a friend to help.