Use Memcached to cache MySQL Data

Source: Internet
Author: User
Memcached uses libevent to balance any number of open links and uses non-blocking network I/O to implement reference counting for internal objects (therefore, for various clients, objects

Memcached uses libevent to balance any number of open links and uses non-blocking network I/O to implement reference counting for internal objects (therefore, for various clients, objects

Memcached is a distributed memory object cache system, which is usually used for dynamic Web applications to reduce database load.

Memcached is a hashmap based on a storage key pair. When the table is full, it is replaced by the LRU (least recently used) algorithm.

Memcached uses libevent to balance any number of open links, and uses non-blocking network I/O to implement reference counting for internal objects (therefore, for various clients, objects can be in a variety of States), and use their own page block distributors and hash tables. Therefore, the virtual memory will not generate fragments, and the time complexity of virtual memory allocation can be guaranteed to be O (1 ).

The following describes how to install memcached in CentOS and test the Memcache cache mechanism in combination with mysql and php.

1. Install memcached

Wget

Wget



Tar xf libevent-1.4.8-stable.tar.gz

Cd libevent-1.4.8-stable

./Configure

Make & make install

Ln-sv/usr/local/lib/libevent */usr/lib/



Tar xf memcached-1.4.15.tar.gz

Cd memcached-1.4.15

./Configure

Make & make install



Start memcached

[Root @ www ~] # Memcached-d-unobody-m50-p000011-P/tmp/memcached. pid

Note:

-D run in standalone Mode

-U to which users to start

-Memory size occupied by m (default value: 100)

-P listening port number

-P specifies the pid position

If no message is reported, check netstat-tnlp.

2. Install the memcached extension for php (I use php5.4.4)

[Root @ www ~] # Wget

[Root @ www ~] # Tar zxvf memcache-2.2.5.tgz

[Root @ www ~] # Cd memcache-2.2.5/

[Root @ www ~] #/Usr/local/php/bin/phpize

[Root @ www ~] #./Configure -- with-php-config =/usr/local/php/bin/php-config

[Root @ www ~] # Make

[Root @ www ~] # Make install

Add the memcache extension to the configuration file. The command is as follows:

Sed-I's # extension_dir = ". /"# extension_dir ="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20100525/"\ nextension =" memcache. so "# '/usr/local/php/etc/php. ini

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.