Absrtact: Because the data stored by the database is more and more large, the query speed becomes more and more slow, so there is a need for Linux caching server application, this article introduces the installation of memcached and simple use.
This article only introduces Memcached's PHP API and wants to see other API files on memcached, please visit http://www.danga.com/memcached/
Directory
I. Environmental requirements
Second, download the relevant software
III. Installation and Configuration
1. Installation memcached
2. Install memcache PHP Module
3. Test scripts
Four, about this article
++++++++++++++++++++++++++++++++++++++++
Body
++++++++++++++++++++++++++++++++++++++++
I. Environmental requirements
Installation memcached requires Libevent library support, so check to see if Libevent is installed before installing memcached. The test environment also requires PHP support, this article assumes that PHP has been installed into the/usr/local/php directory, that is, when compiling PHP using the Perfix parameter to specify the directory (--prefix=/usr/local/php)
Second, download the relevant software
memcached Download Address: http://www.danga.com/memcached/
memcache PHP module Download address: Http://pecl.php.net/package/memcache recommended to use version 1.5
Libevent Download Address: http://www.monkey.org/~provos/libevent/
This article no longer describes how to install Libevent
III. Installation and Configuration
1. Installation 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
To start the service after the installation is complete
root@tonyvicky:# Cd/usr/local/memcached/bin
root@tonyvicky:#. /memcached-d-M 50-p 11211-u Root
Parameter Description-m specifies the number of megabytes of cache space to use;-p specifies the port to listen to, and-u specifies which user to run
2. Install 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 installation, there will be a hint like this:
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
Keep this in mind, then modify the php.ini, and put
Extension_dir = ". /”
Amended to
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
and add a row
Extension=memcache.so
3. Test scripts
Write a PHP program to test yourself.
《? Php
$memcache = new Memcache; Create a Memcache object
$memcache-"Connect" (' localhost ', 11211) or die ("could not Connect"); Connecting memcached servers
$memcache-"Set" (' Key ', ' test '); Set a variable to memory, the name is the key value is test
$get _value = $memcache-"Get" (' key '); To remove the value of a key from memory
echo $get _value;
? 》