Applications of cache servers in Linux

Source: Internet
Author: User
Abstract:As the amount of data stored in the database increases and the query speed slows down, it is necessary to use the cache server application. This article describes how to install and use memcached.

This article only introduces the php api of memcached, to view other API files about memcached, please visit http://www.danga.com/memcached/

Directory

    I. environment requirements
    2. Download related software
    Iii. installation and configuration

     

      1. Install memcached
      2. Install the memcache PHP Module
      3. Test script

    4. About this article


++
Body
++

I. environment requirements
Installing memcached requires the support of the libevent library. Therefore, check whether libevent is installed before installing memcached. The test environment also requires the support of PHP. This article assumes that PHP has been installed in the/usr/local/PHP Directory, that is, when compiling PHP, use the Perfix parameter to specify the directory (-- prefix =/usr/local/PHP)

2. Download related software

Memcached:Http://www.danga.com/memcached/
Memcache PHP module:Http://pecl.php.net/package/memcache recommended version 1.5
Libevent:Http://www.monkey.org /~ Provos/libevent/

This article no longer describes how to install libevent

Iii. installation and configuration

1. Install memcached

root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install

 

Start the service after installation.

root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root

 

Parameter description-M specifies the MB of cache space used;-P specifies the port to be listened on;-u specifies the user to run

2. Install the memcache PHP Module

root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install

 

After the installation is complete, a message like this will be prompted:

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/

 

Remember this, modify PHP. ini, and

extension_dir = "./"

 

Change

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"

 

Add a row

extension=memcache.so

 

3. Test script

Write a PHP program and test it.

<? PHP
$ Memcache = new memcache; // create a memcache object
$ Memcache-> connect ('localhost', 11211) or die ("cocould not connect"); // connect to the memcached Server
$ Memcache-> set ('key', 'test'); // set a variable to the memory. The name is key and the value is test.
$ Get_value = $ memcache-> get ('key'); // retrieves the key value from the memory.
Echo $ get_value;
?>

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.