1The concept memcache is an efficient distributed memory object caching system that supports the ability to put PHP's various data (arrays, objects, basic data types) in its managed memory
2Install Step 1, download the Php_memcache.dll file and put it into PHP/ext/Directory 2, open php.ini file here to enable memcache.dll extension extension=Php_memcache.dll3. Code Usage<?PHP//1. Instantiate a Memcache object$mem=NewMemcache; //2. Connect to the specified memcache$mem->connect ("127.0.0.1",11211); //0 means uncompressed data, if compressed memcache_compressed is used if(! $mem->add ("name","test1",0, -) {echo"name already exists."; }Else{echo"ok!"; }//can be placed in numeric values if(! $mem->add (" Age", -,0, -) {echo"Age already exists."; }Else{echo"ok!"; }//can be placed in a Boolean if(! $memSet("OK",true,0, -) {echo"OK save successful"; }Else{echo"ok!"; }//put an array$arr 1=array ("AA"="Beijing","BB"="Tianjin"); //The array is serialized, in the network transmission, in order to ensure that the data type is not lost,//It is serialized first and then occurs. //$arr 1=serialize ($arr 1);$arr 2=Json_encode ($arr 1); Print_r ($arr 2); $mem->add ("arr", $arr 1,memcache_compressed, -); //Objectrequire"Person.class.php"; $person=NewPerson (Ten,"xiaoming"); $mem->add ("Per1", $person, memcache_compressed, -); //removed$per 2= $memGet("Per1"); Var_dump ($per 2); Echo"Object name =". $per 2->name; //string, Int,float, Boolean array object null resource//cannot put the resource type into Memcache$con=mysql_connect ("localhost","Root","Root"); Echo"<br/>"; Var_dump ($con); $mem->add ("MyLink", $con);?>about how to use multiple memcached cache servers.<?PHP $mem=NewMemcache (); //If we have a website, multiple memached cache systems are required. //$mem->connect ("localhost", 11211); (Connect immediately to port 11211 on localhost)$mem->addserver ("192.168.1.100",11211);//->10m$mem->addserver ("192.168.1.200",11211); $mem->addserver ("192.168.1.222",11211); //Create multiple Memcache services to use. //Addserver is automatically placed on each server according to the load Balancing algorithm$mem->add ("name","ZS",0, -);?>Note:string,int,float, the Boolean arrayObject NULLResource in addition to the resource can not be stored, all other.
Memcache (using PHP operation Memcache)