1. Install the memcache php component first.
Wget http://pecl.php.net/get/memcache-3.0.6.tgz
Tar-zxvf
Memcache-3.0.6.tgz
CD
Memcache-3.0.6
/Usr/local/PHP/bin/phpize
&./Configure -- enable-memcache & make
Note: The system will prompt that PHP-onfig cannot be found, and then add -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
The parameter is enough.
/Usr/local/PHP/bin/phpize
&./Configure -- enable-memcache
-- With-PHP-Config =/usr/local/PHP/bin/PHP-config &&
Make
CP
Modules/memcache. So/usr/local/PHP/lib/PHP/extensions
Note: there is also a way to install it, but I have not tried it, that is, execute
Yum install php5-memcache
2.
Modify the php. ini file
Touch
/Etc/PHP. d/memcached. ini
Echo 'extension = memcache. so'>/etc/PHP. d/memcached. ini
Note: You can also directly go to PhP. ini
Add extension = memcache. So.
3.
PHP Test File
<? PHP
$ Memcache = new memcache;
$ Memcache-> connect ('localhost', 11211)
Or die ("cocould 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, 10)
Or die ("failed to save data at the server ");
Echo "store data in the cache (data will expire in 10 seconds) <br/> \ n ";
$ Get_result = $ memcache-> get ('key ');
Echo "data from the cache: <br/> \ n ";
Var_dump ($ get_result );
?>
4.
Attach the memcached installation method (not under centos)
#
Download & Install libevent (memcached dependency)
Wget http://www.monkey.org /~ Provos/libevent-1.4.8-stable.tar.gz
Tar xfz libevent-1.4.8-stable.tar.gz
CD libevent-1.4.8-stable
./Configure & make & sudo make install
# Create a symlink to libevent
Sudo ln-S/usr/local/lib/libevent-1.4.so.2/usr/lib
# Download & Install memcached
Wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
Tar xfz memcached-1.2.6.tar.gz
CD memcached-1.2.6
./Configure & make & sudo make install
# Run memcached as a daemon (D = daemon, M = memory, u = user, L = IP to listen to, P = port)
Memcached-D-M 1024-u root-l 127.0.0.1-P 11211