Install memcache extension for php

Source: Internet
Author: User
Tags zts
Linux: Software libevent-1.4.6-stable.tar.gz (monkey.org ~ Provoslibevent?memcache-2.2.3.tgz(pecl.php.netpackagememcache=memcached-1.2.6.tar.gz (www. danga. commemcached) Installation configuration 1.

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.

Linux:

InstallEnvironment
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)


InstallConfiguration

1.InstallLibevent
# 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.InstallMemcached
# 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.InstallPhp memcacheExtension

You can use the pecl that comes with php.InstallProgram
#/Usr/local/servers/php5/bin/pecl install memcache

You can also use the source codeInstall
# 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

InstallThere will be a prompt like this after:
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

Windows:

Download the stable version of memcache for windows and decompress it to a disk, for example, in d: \ memcached

2. Enter d: \ memcached \ memcached.exe-d install on the terminal (that is, the cmd command interface)Install

3. Enter c: \ memcached \ memcached.exe-d start to start.

NOTE: in the future, memcached will be used as a windows Service and will be automatically started every time it is started. In this way, the server hasInstallFinished.

4. Download php_memcache.dll. Find the corresponding php version file by yourself.

5. Add a line of extension = php_memcache.dll to php. ini.

6. Restart Apache and check phpinfo. If memcache exists, it indicatesInstallSuccessful!


Test Module

$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 12000) or die ("cocould not connect ");

$ Version = $ memcache-> getVersion ();
Echo "Server's version:". $ version ."
\ 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)
\ N ";

$ Get_result = $ memcache-> get ('key ');
Echo "Data from the cache:
\ N ";

Var_dump ($ get_result );

?>

Display result:

Server's version: 1.4.4-14-g9c660c0
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

----------------

The server side is memcached, and the client side can be considered as php_memcache.dll.

Php_memcache.dll provides a set of functions for caching, extraction, and deletion of cache operations. Through these functions, the data is finally stored inInstallA machine with the memcached service can be a local machine or a machine on another network.

Memadmin is a powerful tool for viewing memcached servers. (Written in php + jquery)

2cto accessories: http://up.2cto.com/2011/1124/20111124050347851.rar

Baidu Network Disk download: http://pan.baidu.com/s/14HGPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.