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 http://skadns.googlecode.com/files/libevent-1.4.8-stable.tar.gz
Wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
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 http://pecl.php.net/get/memcache-2.2.5.tgz
[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