How Memcached works and how to install and deploy it in Linux
Memcached is a high-performance distributed memory object Cache System for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of reads to the database, thus improving the speed of dynamic and database-driven websites. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in C, but the client can write it in any language and communicate with the daemon through memcached protocol. Memcached lacks authentication and security control, which means that the memcached server should be placed behind the firewall. The workflow of memcache is as follows: first check whether the client's request data is in memcached. If yes, directly return the request data without any operations on the database; if the requested data is not in memcached, check the database, return the data obtained from the database to the client, and cache the data to memcached, must be explicitly implemented by the Program). Data in memcached is updated at the same time each time the database is updated to ensure consistency. When the memory space allocated to memcached is Used up, LRU (Least Recently Used, Least Recently Used) is Used) when a policy is added with an expiration Policy, the invalid data is replaced first, and then the data that has not been used recently is replaced.
Add memcache module to php
[Root @ bkjia ~] # Echo $ PATH
/Usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: /usr/local/lnmp/mysql/bin:/root/bin
[Root @ bkjia ~] # Vim/etc/profile
79 PATH = $ PATH:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[Root @ bkjia ~] # Source/etc/profile
[Root @ bkjia ~] # Tar zxf memcache-2.2.5.tgz
[Root @ bkjia ~] # Cd memcache-2.2.5
[Root @ bkjia memcache-2.2.5] # phpize
Processing ing:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[Root @ bkjia memcache-2.2.5] #./configure -- enable-memcache
[Root @ bkjia memcache-2.2.5] # make & make install
[Root @ bkjia memcache-2.2.5] # ll
/Usr/local/lnmp/php/lib/php/extension/ no-debug-non-zts-20100525/memcache. so
-Rwxr-xr-x 1 root 259040 Jan 16 memcache. so
[Root @ bkjia memcache-2.2.5] # vim/usr/local/lnmp/php/etc/php. ini
845 extension = memcache. so
[Root @ bkjia memcache-2.2.5] #/etc/init. d/fpm reload
[Root @ bkjia memcache-2.2.5] # cd/usr/local/lnmp/nginx/html
[Root @ bkjia html] # vim index. php
1 <? Php
2 phpinfo ()
3?>
Open this php page in the browser to view memcache-related information.
[Root @ bkjia html] # nginx-t
Nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/usr/local/lnmp/nginx/conf/nginx. conf test is successful
[Root @ bkjia html] # nginx-s reload
[Root @ bkjia ~] # Php-m | grep memcache # indicates that the memcache module is successfully added to php.
Memcache
Install memcached
Root@bkjia.com ~ # Yum install-y memcached
Root@bkjia.com ~ #/Etc/init. d/memcached start
Starting memcached: [OK]
Root@bkjia.com ~ # Vi/etc/sysconfig/memcached
PORT = "11211"
USER = "memcached"
MAXCONN = "1024"
CACHESIZE = "64"
OPTIONS = ""
~
Root@bkjia.com ~ # Memcached-tool 127.0.0.1: 11211 stats
# Wagner. 0.0.1: 11211 Field Value
Accepting_conns 1
Auth_cmds 0
Auth_errors 0
Bytes 0
Bytes_read 799
Bytes_written 38165
Cas_badval 0
Cas_hits 0
Cas_misses 0
Pai_flush 0
Performance_get 0
Performance_set 0
Conn_yields 0
Connection_structures 11
Curr_connections 10
Curr_items 0
Decr_hits 0
Decr_misses 0
Delete_hits 0
Delete_misses 0
Evictions 0
Get_hits 0
Get_misses 0
Incr_hits 0
Incr_misses 0
Limit_maxbytes 67108864
Listen_disabled_num 0
Pid 5154
Pointer_size 64
Rusage_system 0.121981
Rusage_user 0.068989
Threads 4
Time 1469970117
Total_connections 93
Total_items 0
Upload 5637
Version 1.4.4
Memcached is successfully installed.
Install and configure Memcached source code in CentOS 6.6
Memcached installation and startup script
Performance problems of using Memcached in PHP
Install Memcached in Ubuntu and its command explanation
Install and apply Memcached
Use Nginx + Memcached's small image storage solution
Getting started with Memcached
For details about Memcached, click here
Memcached: click here
This article permanently updates the link address: