Preface
Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read.
Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.
Of course memcached is divided into server and client . The server is used to store the cache and the client is used to manipulate the cache.
There are two common implementations of clients.
The first is to use PHP code according to the service side of the communication rules to write their own.
The second is the installation of the PHP extension Library (php-memcached).
Directory
First, Centos7 from the zero compiler configuration memcached
First, the preparatory work
Create the directory source and package, respectively, to put the source code and the compiled file
mkdir mkdir /package/
Second, start the installation
2.1 Installing Redis
[Official website] http://www.redis.io/
Command flow:
CD /source/wget http://download.redis.io/releases/redis-3.2.0.tar.gztar -zxvf Redis-3.2.0.tar.gz
CD redis-3.2.0makeCD src
2.2 Combination of generated files
After compilation, there are four executable files Redis-server, Redis-benchmark, REDIS-CLI, and redis.conf in the SRC directory. And then copy it to a directory.
Command flow:
Mkdir/package/redis
CP Redis-server /package/rediscp redis-benchmark/package/rediscp redis-cli / package/rediscp redis.conf /package//package/redis
This chapter summarizes:
It is easy to compile the memcached server with the above operation. At this point, you can open the server to work.
2048 127.0. 0.1 11211 -u root-c 1024–p/tmp/memcached.pid
Start parameter Description:-The D option is to start a daemon. -m allocated the amount of memory used by Memcache, in MB, default 64MB. -L monitor the IP address. (Default: Inaddr_any, all addresses)-p sets the port of the Memcache TCP listener, preferably more than 1024. -u run memcache user, if current is root, you need to use this parameter to specify the user. -TheC option is the maximum number of concurrent connections to run, and the default is 1024. -p Settings Save the PID file for Memcache.
Third,memcached (client- side article)
The first type: PHP Code
This method is the simplest way to implement the client, directly download my "sl_memcached" class library include to call the relevant objects in their own projects.
Of course, you can also implement it in other languages. This is not the place to talk.
Here's how to use it:
<?PHPinclude(' memcached.class.php ');$memcached=NewSl_memcached ();//instantiating an object$memcached->connect (' 127.0.0.1:11211 ');//connecting the memcached service side$memcached->set (' Key1 ', ' I am the key value of happiness ');//set the key value$memcached->set (' Key2 ', ' I'm going to be deleted ');//set the key value$memcached->delete (' Key2 ');//Delete a key valueVar_dump($memcached->get (' Key1 '));//Get key valueVar_dump($memcached->get (' Key2 '));//Get key value?>
Output:
String (21) "I am the key value of happiness"
Null
4.1 Installing Zlib
[Official website] http://zlib.net/
Command flow:
CD /source/
wget tar -zxvf zlib-1.2.8.tar.gz
#./configure--prefix=/package/zlib
Make
Make Install
Start Configuration php-memcached
Open php.ini
# Vi/lnmp/php/etc/php.ini
Add the following in the appropriate location
Extension =/lnmp/php/lib/php/extensions/no-debug-non-zts-20151012/memcached.so
------------------------------------------------------------
V. Common Mistakes
------------------------------------------------------------
5.1 Unable to load dynamic library ' memcached.so '-libmemcached.so.11:cannot open Shared object file:no such file or di Rectory in Unknown No line 0
Description: No additional libraries found for PHP memcached.so the required dynamic library libmemcached.so.11. The above error generally does not set the libmemcached directory to an environment variable.
We add it to the environment variable ld_library_path and we're done.
# export ld_library_path=/package/libmemcached/lib: $LD _library_path
Original Centos7 Configuring Redis from zero compilation