1. Preparation required before installation:
Required Softwarelibevent-1.4.6 This version of the web is not found, so install the latest version libevent-2.0.22Libevent-1.4.6-stable.tar.gz (http://monkey.org/~provos/libevent/)
Memcache-2.2.3.tgz (Http://pecl.php.net/package/memcache)
Memcached-1.2.6.tar.gz (http://www.danga.com/memcached/)
2. Installing Libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# CD Libevent-1.4.6-stable
#./configure--prefix=/usr/local/libevent
# Make && make install
3. Installing memcached
# tar ZXVF memcached-1.2.6.tar.gz
# CD memcached-1.2.6
#./configure--prefix=/usr/local/memcached--with-libevent=/usr/local/libevent
# Make && make install
4. Run memcached[ Red look carefully ]
#/usr/local/memcached/bin/memcached -d-m 128-l localhost-p 11211-u root
If you encounter a problem running memcached, the error message is as follows:
/usr/local/memcached/bin/memcached:error while loading shared libraries:libevent-1.4.so.2:cannot open Shared object fi Le:no such file or directory
Run ld_dubug=libs to know the load path of the library when the memcached starts. Specific as follows:
# ld_debug=libs/usr/local/memcached/bin/memcached-v
Then create a link to libevent-1.4.so.2 and then run memcached:
# ln-s/usr/local/libevent/lib/libevent-1.4.so.2/lib/libevent-1.4.so.2
5. Installation of PHP Memcache
PHP Environment using memcached:
First, PHP has a name called
Extension of the Memcache
, you need to take the enable-memcache[=dir] option under Linux, and Window will remove the comment from the front of the Php_memcache.dll in php.ini to make it available.
The second is the direct use of
Php-memcached-client
But it's a little less efficient than the expansion library.
This is an extension of memcache.
You can use the PECL installer that comes with PHP
#/usr/local/php5/bin/pecl Install Memcache
can also be installed from the source code
# tar zxf memcache-2.2.3.tgz
# CD memcache-2.2.3
#/usr/local/php/bin/phpize
#./configure--enable-memcache--with-php-config=/usr/local/php/bin/php-config
#make
#make Install
Return: Installing Shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
Indicates a successful installation!
6. Inspection services
(1) To view the Memcache service initiated:
Netstat-lp | grep memcached
(2) View the Memcache process number (depending on the process number, you can end the Memcache service: "kill-9 process number")
Ps-ef | grep memcached
Adding Memcache extensions to PHP.ini
Extension=memcache.so
Test:
Phpinfo ();
Program test:
<?php
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect(‘localhost‘, 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set(‘key‘, ‘test‘); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get(‘key‘); //从内存中取出key的值
echo $get_value;
?>Complete!
Install memcache under Linux (PHP version 5.3)