In many occasions, we will hear the name memcached, but many students just heard, and did not use or actually understand, only know it is a very good stuff. Here is a brief introduction, memcached is an efficient and fast distributed memory object caching system, mainly used to speed up web dynamic applications. Today we'll start with a simple discussion of the use of memcached.
-->
1. Add Expansion pack
The code is as follows:
Php_memcache.dll
2. Add in PHP.ini
The code is as follows:
Extension=php_memcache.dll
3. The procedure
The code is as follows:
<?php
Create a Mem object instance
$mem =new Memcache;
if (! $mem->connect ("10.18.110.213", 11211)) {
Die (' Connection failed! ');
}
Increase
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. Adding an array
In addition to the array is, as required. Want the serial number into,
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. Add a null Boolean value
/* IF ($mem->set (' Key1 ', false,memcache_compressed,60)) {
Echo ' Add boolean ok ';
}*/
6. The resource type is put in.
/* $con =mysql_connect ("127.0.0.1", "root", "root");
if (! $con) {
Die (' Connection database failed ');
}
Var_dump ($con);
echo "<br/>";
if ($mem->set (' Key1 ', $con, memcache_compressed,60)) {
Echo ' Add resource ok ';
}*/
Inquire
$val = $mem->get (' Key1 ');
Modify
You can use the 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 ';
}
Above is the introduction of the use of memcache in PHP, I hope you can help.