Linux under PHP extension installation memcache module

Source: Internet
Author: User
Tags zts

Linux under PHP extension installation memcache module
Roid

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


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.2.6
Store data in the cache (data would expire in seconds)
Data from the cache:

Object (StdClass) [3] public ' str_attr ' = = String ' Test '

Linux under PHP extension installation memcache module

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.