PHP using memcached

Source: Internet
Author: User

1. Add an expansion pack

Php_memcache.dll

2. Add in 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 "<br/>";    if ($mem->set (' Key1 ', $con, memcache_compressed,60)) {echo ' Add resource ok '; }*/    //Enquiry    $val=$mem->get (' Key1 ');//Modify//can use 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 '; }

PHP using memcached

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.