php5.3 installation libmemcached extension method and simple instance _php tutorial

Source: Internet
Author: User
Tags delete key key string php memcached
Libmemcached is a memcached library, client library, C and C + + language implementation of the client library, with low memory occupancy, thread safety, and provides full support for memcached functionality. It also employs a variety of command-line tools: Memcat, Memflush, MEMRM, MemStat, and memslap (load generation). Library has been designed to let different hashing methods pair keys, split the keys, and use a unified hash distribution

Libmemcached-based PHP memcache client has many advantages

Hash Consistent storage
Multi Get/set
• Automatically hashes the key to int, bypassing the limit of Memcache key string by default less than 255Byte
Long time no server configuration, always thought that libmemcached PHP memcached has been included in the basic installation package, in the end also need to compile themselves. The whole installation process a lot of dark pits, tried several times to succeed

Two-Step installation

• Install libmemcached, target so and header files
• Install memcachedphp extensions
Libmemcaced is divided into two major versions of 0.x and 1.x, 1.x version from 2011-09-28 onwards, the compilation is very troublesome, need gcc4.0 above the special configuration, compile extremely slow. The 0.x version is much simpler, the highest version is 0.53, so choose Install 0.53

Acura always appear in pairs, PHP memcahed also starting from 2.1.0, requires libmemcached must be 1.0.x version

libmemcaced I use 0.53, that php-memcahed choose 2.0.0. Version maintenance of open source software is a lousy account.

Installing libmemcached

The code is as follows Copy Code
wget https://launchpad.net/libmemcached/1.0/0.53/+download/libmemcached-0.53.tar.gz
Tar Xvfz libmemcached-0.53.tar.gz
CD libmemcached-0.53
./configure--prefix=/opt/libmemcached
Make && make install


Installing PHP Extensions

The code is as follows Copy Code

wget http://pecl.php.net/get/memcached-2.0.0.tgz
Tar zvxf memcached-2.0.0.tgz
CD memcached-2.0.0/
./configure--enable-memcached--with-php-config=/usr/local/php/bin/php-config--with-libmemcached-dir=/opt/ libmemcached/
Make && make install


Make install installs the memcached.so to ${php install dir}/extensions/no-debug-non-zts-20090626/, which differs depending on the PHP version

The last step, modify the php.ini, plus extension=memcached.so

With the face we have installed to see a simple example

The code is as follows Copy Code


#include
2 #include
3 #include
4
5 using namespace Std;
6
7 int main (int argc,char *argv[])
8 {
9//connect Server
Ten Memcached_st *MEMC;
Memcached_return RC;
Memcached_server_st *server;
time_t expiration;
uint32_t flags;
15
MEMC = Memcached_create (NULL);
+ Server = Memcached_server_list_append (NULL, "localhost", 11211,&RC);
Rc=memcached_server_push (Memc,server);
Memcached_server_list_free (server);
20
string key = "Key";
String value = "Value";
size_t value_length = Value.length ();
size_t key_length = Key.length ();
25
26
//save data
Rc=memcached_set (Memc,key.c_str (), Key.length (), Value.c_str (), Value.length (), expiration,flags);
if (rc==memcached_success)
30 {
cout<< "Save Data:" < <><"> <>
32}
33
//get data
char* result = Memcached_get (Memc,key.c_str (), KEY_LENGTH,&AMP;VALUE_LENGTH,&AMP;FLAGS,&AMP;RC);
if (rc = = memcached_success)
37 {
cout<< "Get Value:" < <><"> <>
39}
40
//delete data
Rc=memcached_delete (Memc,key.c_str (), key_length,expiration);
if (rc==memcached_success)
44 {
cout<< "Delete key:" < <><"> <>
46}
47
//free
Memcached_free (MEMC);
return 0;
51}
52
53

Compilation: g++-O testmemcached testmemcached.cpp-lmemcached
Run:./testmemcached
Result: Save data:value sucessful!
Get Value:value sucessful!
Delete Key:key sucessful!


Precautions

It should be noted that libmemcached is not a libmemcache, they are two different client libraries, the former is now more active development, the latter has not been updated for a long time.

Memcached is a high-performance, distributed memory object caching system that reduces access to the database through memory data caching, thus increasing the speed of dynamic content application sites. Memcached official development released, just the application of the server-side program, it released the server-side connection read-write protocol, client implementation, according to the dynamic Content application site using the dynamic script different, but there are many, specific list, can view the official website.

http://www.bkjia.com/PHPjc/629821.html www.bkjia.com true http://www.bkjia.com/PHPjc/629821.html techarticle libmemcached is a memcached library, client library, C and C + + language implementation of the client library, with low memory occupancy, thread safety, and provides full support for memcached functionality. ...

  • 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.