Memcache is a high-performance distributed memory object cache system. By maintaining a unified and huge hash table in the memory, memcache can be used to store data in various formats, including image, video, file, and database retrieval results.
To develop and use memcache, We must install memcache server and PHP memcache extensions.
1. First install the memcache Server:
$ Sudo apt-Get install memcached
Then you can run the following command to enable memcache:
$ Memcached-l 127.0.0.1-P 11211-D-u nobody-P/var/run/memcached. PID-M 64 m-C 1024-VV
Explain the meanings of several parameters:
-L the IP address of the listener. 127.0.0.1 is the IP address of my local server. If you need multiple servers to read the cached data of this memcached, you must set this IP address.
-P memcached listening TCP port
-D run in daemon mode, SetProgramIn the background
-U memcached running user. I set nobody. By default, memcache is not allowed to log on as a root user.
-P memcached PID file path
-Maximum memory available for M memcached
-C memcached maximum number of connections that can be accepted at the same time
If you want to access memcached through socket, you must remove the-L and-P parameters at startup and add the-S parameter:
-S memcached socket file path
-VV: Display debug information
2. Install the PHP memecache Client
$ Sudo apt-Get install php5-memcache
Restart FastCGI and use phpinfo () to see the memcache extension.