PHP uses memcached and php uses memcached

Source: Internet
Author: User

PHP uses memcached and php uses memcached

1. Add extension package

Php_memcache.dll

2. Add in PHP. INI

Extension = php_memcache.dll

3. Program

 

<? Php // 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 an array // Add an array as needed. if you want the serial number to be placed in, // serialize <=> unserialize, you can also use json_encode <=> json_decode $ arr = array ("bj", 'tj ') as needed '); 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 a null Boolean value/* if ($ mem-> set ('key1', false, MEMCACHE_COMPRESSED, 60) {echo 'add Boolean OK ';} * // 6. put the resource type in. /* $ con = mysql_connect ("127.0.0.1", "root", "root"); if (! $ Con) {die ('database connection failed');} var_dump ($ con); echo "<br/>"; 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 "<br/>"; if ($ mem-> delete ('key14 ')) {echo 'key14 delete';} else {echo 'key14 does not exist ';}

 

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.