1, first download memcached server
wget http://www.memcached.org/files/memcached-1.4.20.tar.gz
Yum-y Install Libevent
Yum-y Install Libevent-devel
./configure && make && make install
Test:
Telnet 127.0.0.1 11211
Trying 127.0.0.1 ...
Connected to 127.0.0.1.
Escape character is ' ^] '.
That's a success.
Start/End
Memcached-d-M 10-u root-l 172.25.43.71-p 11200-c 256-p/tmp/memcached.pid
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, 10MB
-U is the user running memcache, this is root
-L is the server IP address of the listener, if there are multiple addresses, this specifies the IP address of the server 192.168.0.122
-P is the port that sets Memcache listening, which is set to 12000, preferably more than 1024 ports
The-c option is the maximum number of concurrent connections, the default is 1024, where 256 is set according to the load on your server
-P is a PID file that is set to save Memcache
Kill ' Cat/tmp/memcached.pid '
2. Download PHP memcache
wget http://pecl.php.net/get/memcache-2.2.7.tgz
Tar zxvf memcache-2.2.7.tgz
CD memcache-2.2.7
/usr/local/php/bin/phpize//compile with Phpize
./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache
Make && make install
Put memcache.so in php.ini extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so
3. Get all the keys in the Memcache
$oMem = new Memcache;
$host = ' 172.25.43.71 ';
$port = ' 11200 ';
$oMem->connect ($host, $port);
$items = $oMem->getextendedstats (' items ');
$items = $items ["$host: $port"] [' items '];
foreach ($items as $key = = $values) {
$number = $key;
$str = $oMem->getextendedstats ("Cachedump", $number, 0);
Var_dump ($STR);
$line = $str ["$host: $port"];
if (Is_array ($line) && count ($line) >0) {
foreach ($line as $key = = $value) {
echo $key. ' = ';
Print_r ($oMem->get ($key));
echo "\ r \ n";
}
}
}
PHP Installation Memcache Extensions