Install the memcache module for PHP extension in linux. Software libevent-1.4.6-stable.tar.gz (monkey.org ~ Provoslibevent) memcache-2.2.3.tgz (pecl. php. netpackagememcache) memcached-1. 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)
Install configurations
1. install 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. install 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. run memcached
#/Usr/local/servers/memcached-d-m 128-l localhost-p 11211-u root
-D run memcached in daemon mode;
-M: Set the memory size available for memcached, in MB;
-L set the IP address of the listener. if it is a local machine, this parameter is usually not set;
-P: Set the listening port. the default value is 11211. Therefore, you can leave this parameter unspecified;
-U indicates the user;
If you encounter problems when running memcached, the error prompt 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 library loading path when memcached is started. The details are 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 for the 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. install the memcache extension of php
You can use the pecl installation program that comes with php.
#/Usr/local/servers/php5/bin/pecl install memcache
You can also install it 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 the installation is complete, a message like this will be prompted:
Installing shared extensions:/usr/local/servers/php5/lib/php/extension/ no-debug-non-zts-20060922/
Remember this, modify php. ini, and
Extension_dir = "./"
Change
Extension_dir = "/usr/local/servers/php5/lib/php/extensions /"
Add a row
Extension = "no-debug-non-zts-20060922/memcache. so"
5. use phpinfo to view
Test Module
$ Memcache = new Memcache;
$ Memcache-> connect (localhost, 12000) or die ("cocould not connect ");
$ Version = $ memcache-> getVersion ();
Echo "Servers version:". $ version ."
";
$ 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)
";
$ Get_result = $ memcache-> get (key );
Echo "Data from the cache:
";
Var_dump ($ get_result );
?>
Display result:
Servers version: 1.2.6
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
Object (stdClass) [3] public str_attr => string test (length = 4) public int_attr => int 123
Small 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 ....