Linux:
Installation Environment
RHEL 4
PHP 5.2.6
Required Software
Libevent-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/)
Installation configuration
1. Installing Libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# CD Libevent-1.4.6-stable
#./configure--prefix=/usr/local/servers/libevent
# Make && make install
2. Installing memcached
# tar ZXVF memcached-1.2.6.tar.gz
# CD memcached-1.2.6
#./configure--prefix=/usr/local/servers/memcached--with-libevent=/usr/local/servers/libevent
# Make && make install
3. Running memcached
#/usr/local/servers/memcached-d-M 128-l localhost-p 11211-u Root
-D runs memcached in the daemon (daemon) mode;
-M sets the amount of memory that memcached can use, in units of M;
-L Set the listening IP address, if it is native, it is usually possible not to set this parameter;
-P Sets the listening port, which defaults to 11211, so you can also not set this parameter;
-U designated user;
If you encounter a problem running memcached, the error message is as follows:
/usr/local/servers/memcached/bin/memcached:error while loading shared libraries:libevent-1.4.so.2:cannot open shared Object File: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/servers/memcached/bin/memcached-v
10929:find library=libevent-1.4.so.2 [0]; Searching
10929:search Cache=/etc/ld.so.cache
10929:search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/ lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/ Usr/lib/sse2:/usr/lib (System search Path)
10929:trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
10929:trying file=/lib/tls/i686/libevent-1.4.so.2
10929:trying file=/lib/tls/sse2/libevent-1.4.so.2
10929:trying file=/lib/tls/libevent-1.4.so.2
10929:trying file=/lib/i686/sse2/libevent-1.4.so.2
10929:trying file=/lib/i686/libevent-1.4.so.2
10929:trying file=/lib/sse2/libevent-1.4.so.2
10929:trying file=/lib/libevent-1.4.so.2
10929:trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
10929:trying file=/usr/lib/tls/i686/libevent-1.4.so.2
10929:trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
10929:trying file=/usr/lib/tls/libevent-1.4.so.2
10929:trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
10929:trying file=/usr/lib/i686/libevent-1.4.so.2
10929:trying file=/usr/lib/sse2/libevent-1.4.so.2
10929:trying file=/usr/lib/libevent-1.4.so.2
10929:
Then create a link to libevent-1.4.so.2 and then run memcached:
# ln-s/usr/local/servers/libevent/lib/libevent-1.4.so.2/lib/libevent-1.4.so.2
4. Installing the PHP memcache extension
You can use the PECL installer that comes with PHP
#/usr/local/servers/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/servers/php5/bin/phpize
#./configure--enable-memcache=/usr/local/servers/memcached--with-php-config=/usr/local/servers/php5/bin/ Php-config--with-apxs2=/usr/sbin/apxs
# Make && Make Inst
After installation, there will be a hint like this:
Installing Shared extensions:/usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/
Keep this in mind and then modify the php.ini to put
Extension_dir = "./"
Revision changed to
Extension_dir = "/usr/local/servers/php5/lib/php/extensions/"
and add a row
extension= "No-debug-non-zts-20060922/memcache.so"
5. View with Phpinfo
Windows:
Download Memcache's Windows stable version and unzip it under a disk, for example, in d:\memcached
2. Enter the D:\memcached\memcached.exe-d install installation in the terminal (also known as the cmd Command interface)
3. Re-enter: c:\memcached\memcached.exe-d start.
Note: memcached will start automatically every time a service is turned on for Windows. This way the server side is already installed.
4. Download Php_memcache.dll, please find the corresponding PHP version of the file yourself
5. Join a row in php.ini Extension=php_memcache.dll
6. Restart Apache, then check the phpinfo, if there is memcache, then the installation is successful!
Test module
<?php
$memcache = new Memcache;
$memcache->connect (' localhost ', 12000) or Die ("Could not Connect");
$version = $memcache->getversion ();
echo "Server ' s version:". $version. " <br/>\n ";
$tmp _object = new StdClass;
$tmp _object->str_attr = ' Test ';
$tmp _object->int_attr = 123;
$memcache->set (' key ', $tmp _object, False, or Die ("Failed-to-save data at the server");
echo "Store data in the cache (data would expire in seconds) <br/>\n";
$get _result = $memcache->get (' key ');
echo "Data from the cache:<br/>\n";
Var_dump ($get _result);
?>
Show Results:
Server ' s VERSION:1.4.4-14-G9C660C0
Store data in the cache (data would expire in seconds)
Data from the cache:
Object (StdClass) [3] public ' str_attr ' = = String ' Test ' (length=4) public ' int_attr ' = int 123
----------------
The server side is the memcached,client end can be regarded as Php_memcache.dll
Php_memcache.dll provides a set of functions for caching, extracting, deleting caches, and so on, and through these functions, the data is eventually placed on the machine that has the Memcached service installed, either natively or on other networks.
Memadmin is a small tool to view the memcached server, very powerful. (written in Php+jquery)
2cto Accessories: Http://up.2cto.com/2011/1124/20111124050347851.rar
Baidu Network disk Download: Http://pan.baidu.com/s/14HGPS