Connect PHP to memcached in centos

Source: Internet
Author: User

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


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.