PHP module memcached usage guide, memcached usage guide_PHP tutorial

WBOY
Release: 2016-07-13 10:12:09
Original
798 people have browsed it

PHP module memcached usage guide, memcached usage guide

1. Add expansion pack

 php_memcache.dll

2. Add

in PHP.INI

extension=php_memcache.dll

3. Procedure

Copy code The code is as follows:

//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 array
//When adding the array, as needed. I hope the serial number will be put into ,
//serialize<=>unserialize, if needed, you 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.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 null Boolean value
/* if($mem->set('key1',false,MEMCACHE_COMPRESSED,60)){
echo 'Add boolean ok';
}*/
//6. Put the resource type.
/* $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';
}*/

//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 "
";
If($mem->delete('key14')){
echo 'key14 delete';
}else{
echo 'key14 does not exist';
}

Summary:

1. The data of mem service is not synchronized, the data is distributed

2. What data is put into which memcached is determined by the mem object of the client

3. When executing addServer, it does not connect to the mem service immediately, but determines which mem service to connect to after calculation and hashing. Therefore, when you add a large number of servers to the connection pool, there is no extra overhead

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/923903.htmlTechArticlePHP module memcached usage guide, memcached usage guide 1. Add the extension package php_memcache.dll 2. Add in PHP.INI extension=php_memcache.dll 3. The program copy code is as follows: php //Create...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!