ArticleDirectory
I. Software Packages
A) libevent-1.4.13-stable.tar.gz
B) libmemcached-0.27.tar.gz
C) memcached-1.4.5.tar.gz
D) memcache-2.2.5.tgz
Ii. Installation Steps
A) tar zxvf libevent-1.4.13-stable.tar.gz
B) CD libevent-1.4.13-stable
C)./configure make install
D) CD ../
E) tar zxvf libmemcached-0.27.tar.gz
F) CD libmemcached-0.27
G)./configure make install
H) CD ../
I) tar zxvf memcached-1.4.5.tar.gz
J) CD memcached-1.4.5
K)./configure make intall
L) CD ../
M) gzip-D memcache-2.2.5.tgz
N) tar xvf memcache-2.2.5
O) CD memcache-2.2.5
P)/usr/local/PHP/bin/phpize
Q)./configure-enable-memcache-with-PHP-Config =/usr/local/PHP/bin/PHP-config
R) Make make install
S) ln-S/usr/local/lib/libevent-1.4.so.2/usr/lib/libevent-1.4.so.2
T) vi/usr/local/PHP/lib/PHP. ini
Modify extension_dir = "/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613 /"
Added extension = memcache. So
U)/usr/local/Apache/bin/apachectl-K restart
V) The following information can be obtained through the phpinfo () function:
Memcache
Memcache support |
Enabled |
Active persistent connections |
0 |
Version |
2.2.5 |
Revision |
$ Revision: 1.111 $ |
Directive |
Local Value |
Master Value |
Memcache. allow_failover |
1 |
1 |
Memcache. chunk_size |
8192 |
8192 |
Memcache. default_port |
11211 |
11211 |
Memcache. default_timeout_ms |
1000 |
1000 |
Memcache. hash_function |
CRC32 |
CRC32 |
Memcache. hash_strategy |
Standard |
Standard |
Memcache. max_failover_attempts |
20 |
20 |
W) Start the memcache Server
/Usr/local/bin/memcached-D-M 100-uroot-l 59.64.28.78-P 11211-C 256-P/tmp/memcached. PID
-D option is to start a daemon,
-M indicates the amount of memory allocated to memcache. The unit is mb. Here is 100 MB,
-U is the user who runs memcache. Here I am root,
-L is the IP address of the listening server. If there are multiple IP addresses, I have specified the IP address 59.64.28.78,
-P is the port for memcache listening. I have set port 11211 here, preferably port 1024 or above,
-The "C" option is the maximum number of concurrent connections. The default value is 1024. I have set 256 here, which is based on the load of your server,
-P is the PID file for saving memcache. Here I save it in/tmp/memcached. PID.
X) testCode
<? PHP
$ Memcache = new memcache;
$ Memcache-> connect ("59.64.28.78", 11211) or die ("cocould not connect ");
$ Version = $ memcache-> getversion ();
Echo "server's version:". $ version. "\ n ";
$ Member [] = "chenhw ";
$ Member [] = "Linux ";
If (! $ Memcache-> Add ("name", "member", false, 10 )){
$ Member2 = $ memcache-> get ("member ");
} Else {
$ Memcache-> set ("member", $ Member, false, 10 );
Echo "member is not exist ";
}
Echo $ member2 [0];
?>
X) Introduction to the memcached Method
Memcache: Add // Add a value. if it already exists, false is returned.
Memcache: addserver // Add a memcache address
Memcache: Close // close a memcache connection
Memcache: connect // open a connection to memcache
Memcache: decrement // subtract the value of a saved key
Memcache: delete // Delete the key value of a memcache.
Memcache: flush // refresh the items saved on all memcache instances (similar to deleting all saved items)
Memcache: Get // get a key value from memcache
Memcache: getextendedstats // gets the running system statistics of all processes in the process pool.
Memcache: getserverstatus // get the parameters of the running server
Memcache: getstats // get the running status of the current memcache Server
Memcache: getversion // return the version information of the running memcache.
Memcache: Increment // Add the value of a saved key
Memcache: pconnect // open a persistent connection to memcache
Memcache: replace // replace a project that already exists on the memcache server (functions like memcache: Set // Add a value to memcache. if it already exists, overwrite it
Memcache: setcompressthreshold // compress data larger than a certain size
Memcache: setserverparams // modify server parameters during runtime
Iii. Related commands
A) Kill 'cat/tmp/memcached. Pi' to stop the memcached service.
B) echo stats | NC 59.64.28.78 11211 check the memcached running status
C) echo "flush_all" | NC 59.64.28.78 11211 clear all cached data