Application under Linux servers cache cache server

Author: tonyvicky
from: League of Legends Community
Abstract: Because the amount of data stored in the database is growing, query speed will become slower and slower, and therefore there is a need to cache server applications, this article is to introduce Memcached installation and simple usage of.

This paper describes only the memcached API for PHP, want to see the other text files on Memcached API, visit http://www.danga.com/memcached/

table of Contents

First, the environmental requirements
Second, download software
Third, installation and configuration

1, install Memcached
2, install memcache PHP module
3, test scripts

Fourth, on paper


++++++++++++++++++++++++++++++++++++++++
text
+++++++++ +++++++++++++++++++++++++++++++

First, the environmental requirements
to install Memcached need to support libevent library, so please check libevent not installed prior to installing Memcached. Test environment also requires PHP support, this article assumes that PHP has been installed to / usr / local / php directory, which is specified directory (--prefix = / usr / local /use perfix parameters at compile time PHP

Second, download software

Memcached Download: http://www.danga.com/memcached/
memcache PHP module Download: http://pecl.php.net/package/memcache recommend using version 1.5
libevent Download: HTTP: //www.monkey .org / ~ provos / libevent /

This article describes how to install libevent no longer

Third, 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

After installing the service to start

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

Parameter Description -m specify how many megabytes of cache space ;-p use the specified port to listen; -u to specify which user to run

2, the installation module memcache PHP

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 will be similar to this prompt:

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

Remember this, and then modify php.ini, the

extension_dir = "./"

change into

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

And add a line

extension=memcache.so

3, test scripts

Write a PHP program to test it

<?php
$memcache
= new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;
?>



Fourth, on paper
......

Reproduced in: https: //www.cnblogs.com/licheng/archive/2008/01/23/1050149.html

Guess you like

Origin blog.csdn.net/weixin_34015336/article/details/92631046