Applications of cache servers in Linux

Source: Internet
Author: User
Article Title: applications of cache servers in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Abstract: As the amount of data stored in the database increases and the query speed slows down, it is necessary to use the Linux cache server. 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: recommended for http://pecl.php.net/package/memcache 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: # memcached-1.1.12 cd
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: # memcache-1.5 cd
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.


$ 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.