PHP module memcached User Guide, memcached User Guide _ PHP Tutorial

Source: Internet
Author: User
PHP module memcached User Guide, memcached User Guide. PHP module memcached User Guide, memcached User Guide 1. add the extension package php_memcache.dll2. add extensionphp_memcache.dll3 in PHP. the code for program copying is as follows: php creates the PHP module memcached User Guide, memcached User Guide

1. add extension package

Php_memcache.dll

2. add in PHP. INI

Extension = php_memcache.dll

3. program

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! ');
}
// Add
// 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
// When adding an array, you need to add the serial number as needed,
// Serialize <=> unserialize. if needed, you can also use json_encode <=> json_decode
$ Arr = array ("bj", 'TJ ');
If ($ mem-> set ('key1', $ arr, MEMCACHE_COMPRESSED, time () + 31*3600*24 )){
Echo 'add an array ok99111 ';
}
// 4. add an 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. add the resource type.
/* $ Con = mysql_connect ("127.0.0.1", "root", "root ");
If (! $ Con ){
Die ('database connection failed ');
}
Var_dump ($ con );
Echo"
";
If ($ mem-> set ('key1', $ con, MEMCACHE_COMPRESSED, 60 )){
Echo 'add resource OK ';
}*/

// Query
$ Val = $ mem-> get ('key1 ');
// Modify
// Replace can be used
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 the mem service is not synchronized, and the data is distributed.

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

3. when addServer is executed, it does not connect to the mem service immediately, but is computed and hashed before deciding which mem service to connect to. Therefore, when you add a large number of servers to the connection pool, there is no additional overhead.

Example 1. add the extension package php_memcache.dll 2. add extension = php_memcache.dll in PHP. INI 3. the program code is as follows: php // create...

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.